Domanda

I'm attempting to execute my PHPUnit test cases within PHPStorm.

I already added the composer.phar at the root of the project, and tied it into my PHPStorm configuration.

Now I right click on the phpunit.xml.dist and select run..

The module leverages a Logger module I wrote with the following line

// Error occurred, begin a logfile $logger = new Logger(); $writer = new Stream('data/logs/services-api.log'); $logger->addWriter($writer);s This works fine while running on Apache, NGinx, etc...

but in PHPunit it seems to not go where I'm expecting.

```

Zend\Log\Exception\RuntimeException : "data/logs/services-api.log" cannot be opened with mode "a"
#0 ~ZendProject/module/Common/src/Common/Listeners/ApiErrorListener.php(31): Zend\Log\Writer\Stream->__construct('data/logs/servi...')
#1 [internal function]: Common\Listeners\ApiErrorListener::onRender(Object(Zend\Mvc\MvcEvent))

```

I know the data\logs folder is writeable because this code works fine in ZendFramework on Apache... I'm guessing I need to modify my Bootstrap.php somehow?

How can I debug this path, and more importantly refactor my PATH(s) properly for production AND PHPUnit calls?

Edit : I am starting to ouput my current working directory thanks to this tip

https://stackoverflow.com/a/7493389/389976

    public function setUp()
    {
        $this->expectOutputString('');
        print_r("Current Working Directory = " . getcwd());
        print "";
     ...
    }

Giving me some output ...

 Current Working Directory = ~ZendProject/module/ActivityWall/test

How do I properly modify the CWD so that PHPunit can log properly? I'm guessing in BootStrap.php but...?

È stato utile?

Soluzione

Instead of trying to write to the main logfile, I've decided to allow the PHPUnit test it's own test/data/logs/services-api.log

Advantage : This isolates log files and allows me to see with some assurance what is coming from where..

Disadvantage : adds another thing I have to tail -f

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top