When I try to load my config file nothing gets returned and if I don't try load it my test fails because it is trying to access a variable defined in the config file.
vendor/phpunit/phpunit/phpunit --bootstrap config/config.php src/Notification.php tests/NotificationTest -v --debug
Without config
vendor/phpunit/phpunit/phpunit --bootstrap src/Notification.php tests/NotificationTest -v --debug PHPUnit 6.1.1 by Sebastian Bergmann and contributors.
Runtime: PHP 7.0.17
Starting test 'NotificationTest::testEmail'.
E 1 / 1 (100%)
Time: 26 ms, Memory: 4.00MB
There was 1 error:
1) NotificationTest::testEmail
Trying to get property of non-object
src/Notification.php:13
tests/NotificationTest.php:10
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
UPDATE
still errors looking for a variable in config file that i need to load
vendor/phpunit/phpunit/phpunit tests/NotificationTest -v --debug
PHPUnit 6.1.1 by Sebastian Bergmann and contributors.
Runtime: PHP 7.0.17
Starting test 'NotificationTest::testEmail'.
E 1 / 1 (100%)
Time: 26 ms, Memory: 4.00MB
There was 1 error:
1) NotificationTest::testEmail
Trying to get property of non-object
src/Notification.php:13
tests/NotificationTest.php:10
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
UPDATE 2 - new error
vendor/phpunit/phpunit/phpunit --bootstrap config/config.php tests/NotificationTest -v --debug
PHPUnit 6.1.1 by Sebastian Bergmann and contributors.
Runtime: PHP 7.0.17
Starting test 'NotificationTest::testEmail'.
INFO - Message sent
E 1 / 1 (100%)
Time: 128 ms, Memory: 4.00MB
There was 1 error:
1) NotificationTest::testEmail
TypeError: Return value of CCP\Notification::sendEmail() must be an instance of boolean, boolean returned
src/Notification.php:32
tests/NotificationTest.php:11
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
It looks like a problem with strict types and php7, something im not doing right.
source code
<?php
declare(strict_types=1);
namespace CCP;
use CCP\MyMailer;
class Notification{
private $log;
public function __construct(){
global $CFG;
$this->log = $CFG->log;
}
public function sendEmail(string $from, array $to, string $subject, string $body): \boolean{
$mail = new MyMailer;
$mail->setFrom($from);
foreach($to as $value){
$mail->addAddress($value);
}
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->send()) {
$this->log->error(" Message could not be sent for ");
$this->log->error(" Mailer error: ".$mail->ErrorInfo);
return false;
} else {
$this->log->info(" Message sent ");
}
return true;
}
public function emailTest(){
$mail_from = "m.w@mail.com"; # for testing
# code to retrieve the submitter of the subnet
$rcpt_to = ["s.u@mail.com"];
$subject = "CCP :: IAM :: Subnet Request Approved";
$data = "subnet was been approved by the IP Admin";
$this->sendEmail($mail_from, $rcpt_to, $subject, $data);
}
}
?>
fixed, it was bool not boolean