2020-02-03 12:21:04 +08:00
|
|
|
<?php namespace October\Core\Tests;
|
2015-08-08 15:35:22 +10:00
|
|
|
|
|
|
|
use October\Rain\Database\Model as ActiveRecord;
|
2020-02-03 12:21:04 +08:00
|
|
|
use October\Core\Tests\Concerns\CreatesApplication;
|
|
|
|
use October\Core\Tests\Concerns\InteractsWithAuthentication;
|
|
|
|
use October\Core\Tests\Concerns\RunsMigrations;
|
|
|
|
use October\Core\Tests\Concerns\TestsPlugins;
|
2015-08-08 15:35:22 +10:00
|
|
|
|
2019-10-10 00:41:53 +02:00
|
|
|
abstract class PluginTestCase extends TestCase
|
2015-08-08 15:35:22 +10:00
|
|
|
{
|
2020-02-03 12:21:04 +08:00
|
|
|
use CreatesApplication;
|
2019-10-10 00:41:53 +02:00
|
|
|
use InteractsWithAuthentication;
|
2020-02-03 12:21:04 +08:00
|
|
|
use RunsMigrations;
|
|
|
|
use TestsPlugins;
|
2015-08-08 15:35:22 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform test case set up.
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-06-12 10:22:20 -06:00
|
|
|
public function setUp() : void
|
2015-08-08 15:35:22 +10:00
|
|
|
{
|
2020-02-03 12:21:04 +08:00
|
|
|
$this->resetManagers();
|
2019-03-31 14:28:24 +02:00
|
|
|
|
2020-02-03 12:21:04 +08:00
|
|
|
// Create application
|
2017-10-27 18:22:31 -06:00
|
|
|
parent::setUp();
|
2015-08-08 15:35:22 +10:00
|
|
|
|
2020-02-03 12:21:04 +08:00
|
|
|
// Ensure system is up to date
|
|
|
|
if ($this->usingTestDatabase) {
|
|
|
|
$this->runOctoberUpCommand();
|
2015-08-08 15:35:22 +10:00
|
|
|
}
|
|
|
|
|
2020-02-03 12:21:04 +08:00
|
|
|
// Detect a plugin and autoload it, if necessary
|
|
|
|
$this->detectPlugin();
|
|
|
|
|
|
|
|
// Disable mailer
|
|
|
|
\Mail::pretend();
|
2015-08-08 15:35:22 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flush event listeners and collect garbage.
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-06-12 10:22:20 -06:00
|
|
|
public function tearDown() : void
|
2015-08-08 15:35:22 +10:00
|
|
|
{
|
|
|
|
$this->flushModelEventListeners();
|
|
|
|
|
2020-02-03 12:21:04 +08:00
|
|
|
parent::tearDown();
|
2017-04-05 08:23:39 +10:00
|
|
|
}
|
|
|
|
|
2015-08-08 15:35:22 +10:00
|
|
|
/**
|
|
|
|
* The models in October use a static property to store their events, these
|
|
|
|
* will need to be targeted and reset ready for a new test cycle.
|
|
|
|
* Pivot models are an exception since they are internally managed.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function flushModelEventListeners()
|
|
|
|
{
|
|
|
|
foreach (get_declared_classes() as $class) {
|
2015-09-09 19:28:10 +10:00
|
|
|
if ($class == 'October\Rain\Database\Pivot') {
|
|
|
|
continue;
|
|
|
|
}
|
2015-08-08 15:35:22 +10:00
|
|
|
|
2020-02-03 12:21:04 +08:00
|
|
|
$reflectClass = new \ReflectionClass($class);
|
2015-09-09 19:28:10 +10:00
|
|
|
if (
|
|
|
|
!$reflectClass->isInstantiable() ||
|
|
|
|
!$reflectClass->isSubclassOf('October\Rain\Database\Model') ||
|
|
|
|
$reflectClass->isSubclassOf('October\Rain\Database\Pivot')
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-08-08 15:35:22 +10:00
|
|
|
|
|
|
|
$class::flushEventListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
ActiveRecord::flushEventListeners();
|
|
|
|
}
|
2017-04-05 08:23:39 +10:00
|
|
|
}
|