Skip to content

Commit

Permalink
add phpunit listener
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Jul 1, 2019
1 parent ebc6f6e commit 071efc0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<listeners>
<listener class="Tests\Listener" />
</listeners>
<php>
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="MAIL_DRIVER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="APP_CONFIG_CACHE" value="bootstrap/cache/config.phpunit.php" />
</php>
</phpunit>
39 changes: 39 additions & 0 deletions tests/Listener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Tests;

use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\TestListener;
use Illuminate\Contracts\Console\Kernel;
use PHPUnit\Framework\TestListenerDefaultImplementation;

class Listener implements TestListener
{
use CreatesApplication, TestListenerDefaultImplementation;

/**
* Indicates if the listener has already run.
*
* @var bool
*/
protected $alreadyRun = false;

/**
* Called at the start of the test suite.
*
* @param \PHPUnit\Framework\TestSuite $suite
* @return void
*/
public function startTestSuite(TestSuite $suite): void
{
if ($this->alreadyRun) {
return;
}

$this->createApplication()
->make(Kernel::class)
->call('config:cache');

$this->alreadyRun = true;
}
}

0 comments on commit 071efc0

Please sign in to comment.