duan89197 2017-04-24 15:46
浏览 54

phpunit加载配置文件不返回任何内容

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 python变量和列表之间的相互影响
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)