Added tests for Service Providers
This commit is contained in:
27
tests/Providers/AppServiceProviderTest.php
Normal file
27
tests/Providers/AppServiceProviderTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Tests\Cachet\Providers;
|
||||
|
||||
use CachetHQ\Cachet\Providers\AppServiceProvider;
|
||||
use CachetHQ\Tests\Cachet\AbstractTestCase;
|
||||
use GrahamCampbell\TestBenchCore\LaravelTrait;
|
||||
use GrahamCampbell\TestBenchCore\ServiceProviderTrait;
|
||||
|
||||
class AppServiceProviderTest extends AbstractTestCase
|
||||
{
|
||||
use LaravelTrait, ServiceProviderTrait;
|
||||
|
||||
protected function getServiceProviderClass($app)
|
||||
{
|
||||
return AppServiceProvider::class;
|
||||
}
|
||||
}
|
||||
76
tests/Providers/EventServiceProviderTest.php
Normal file
76
tests/Providers/EventServiceProviderTest.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Tests\Cachet\Providers;
|
||||
|
||||
use CachetHQ\Cachet\Providers\EventServiceProvider;
|
||||
use CachetHQ\Tests\Cachet\AbstractTestCase;
|
||||
use GrahamCampbell\TestBenchCore\LaravelTrait;
|
||||
use GrahamCampbell\TestBenchCore\ServiceProviderTrait;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use ReflectionClass;
|
||||
|
||||
class EventServiceProviderTest extends AbstractTestCase
|
||||
{
|
||||
use LaravelTrait, ServiceProviderTrait;
|
||||
|
||||
protected function getServiceProviderClass($app)
|
||||
{
|
||||
return EventServiceProvider::class;
|
||||
}
|
||||
|
||||
public function testIsAnEventServiceProvider()
|
||||
{
|
||||
$class = $this->getServiceProviderClass($this->app);
|
||||
$reflection = new ReflectionClass($class);
|
||||
$provider = new ReflectionClass(ServiceProvider::class);
|
||||
$msg = "Expected class '$class' to be an event service provider.";
|
||||
$this->assertTrue($reflection->isSubclassOf($provider), $msg);
|
||||
}
|
||||
|
||||
public function testListenerMapIsAnArray()
|
||||
{
|
||||
$map = $this->getListenerMap();
|
||||
$this->assertInternalType('array', $map);
|
||||
$this->assertGreaterThan(0, count($map));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testListenerMapIsAnArray
|
||||
*/
|
||||
public function testListenerMapEventsExist()
|
||||
{
|
||||
$map = $this->getListenerMap();
|
||||
foreach (array_keys($map) as $event) {
|
||||
$this->assertTrue(class_exists($event));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testListenerMapIsAnArray
|
||||
*/
|
||||
public function testListenerMapKeysAreSorted()
|
||||
{
|
||||
$map = $this->getListenerMap();
|
||||
$events = array_keys($map);
|
||||
sort($events);
|
||||
$this->assertSame($events, array_keys($map));
|
||||
}
|
||||
|
||||
protected function getListenerMap()
|
||||
{
|
||||
$class = $this->getServiceProviderClass($this->app);
|
||||
$reflection = new ReflectionClass($class);
|
||||
$property = $reflection->getProperty('listen');
|
||||
$property->setAccessible(true);
|
||||
return $property->getValue(new $class($this->app));
|
||||
}
|
||||
}
|
||||
33
tests/Providers/RepositoryServiceProviderTest.php
Normal file
33
tests/Providers/RepositoryServiceProviderTest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Tests\Cachet\Providers;
|
||||
|
||||
use CachetHQ\Cachet\Providers\RepositoryServiceProvider;
|
||||
use CachetHQ\Cachet\Repositories\Metric\MetricRepository;
|
||||
use CachetHQ\Tests\Cachet\AbstractTestCase;
|
||||
use GrahamCampbell\TestBenchCore\LaravelTrait;
|
||||
use GrahamCampbell\TestBenchCore\ServiceProviderTrait;
|
||||
|
||||
class RepositoryServiceProviderTest extends AbstractTestCase
|
||||
{
|
||||
use LaravelTrait, ServiceProviderTrait;
|
||||
|
||||
protected function getServiceProviderClass($app)
|
||||
{
|
||||
return RepositoryServiceProvider::class;
|
||||
}
|
||||
|
||||
public function testMetricRepositoryIsInjectable()
|
||||
{
|
||||
$this->assertIsInjectable(MetricRepository::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user