-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
420 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<?php | ||
|
||
namespace Prokl\ServiceProvider\Tests\Cases; | ||
|
||
use Prokl\ServiceProvider\Services\AppRequest; | ||
use Prokl\TestingTools\Base\BaseTestCase; | ||
use Prokl\TestingTools\Tools\PHPUnitUtils; | ||
use ReflectionException; | ||
|
||
/** | ||
* Class AppRequest | ||
* @package Prokl\ServiceProvider\Tests\Cases | ||
* @coversDefaultClass AppRequest | ||
* | ||
* @since 24.12.2020 Новые тесты. | ||
*/ | ||
class AppRequestTest extends BaseTestCase | ||
{ | ||
/** | ||
* @var AppRequest $obTestObject | ||
*/ | ||
protected $obTestObject; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$_SERVER['REQUEST_URI'] = '/'; | ||
|
||
$this->obTestObject = new AppRequest(); | ||
} | ||
|
||
/** | ||
* getDocumentRoot(). | ||
* | ||
* @return void | ||
*/ | ||
public function testGetDocumentRoot() : void | ||
{ | ||
$result = $this->obTestObject->getDocumentRoot(); | ||
|
||
$this->assertSame( | ||
$_SERVER['DOCUMENT_ROOT'], | ||
$result, | ||
'Неправильный DOCUMENT_ROOT.' | ||
); | ||
} | ||
|
||
/** | ||
* getHttpHost(). | ||
* | ||
* @return void | ||
*/ | ||
public function testGetHttpHost() : void | ||
{ | ||
$result = $this->obTestObject->getHttpHost(); | ||
|
||
$this->assertSame( | ||
$_SERVER['HTTP_HOST'], | ||
$result, | ||
'Неправильный HTTP_HOST.' | ||
); | ||
} | ||
|
||
/** | ||
* initGlobals(). | ||
* | ||
* @return void | ||
* @throws ReflectionException | ||
*/ | ||
public function testGetSuperglobal() : void | ||
{ | ||
$backupGET = $_GET; | ||
$_GET['test'] = 'Y'; | ||
|
||
PHPUnitUtils::callMethod( | ||
$this->obTestObject, | ||
'initGlobals' | ||
); | ||
|
||
$this->assertSame( | ||
'Y', | ||
$_GET['test'], | ||
'Суперглобалы не обработались.' | ||
); | ||
|
||
$_GET = $backupGET; | ||
} | ||
|
||
/** | ||
* initGlobals(). Empty values. | ||
* | ||
* @return void | ||
* @throws ReflectionException | ||
*/ | ||
public function testGetSuperglobalEmpty() : void | ||
{ | ||
$backupGET = $_GET; | ||
$_GET = null; | ||
|
||
PHPUnitUtils::callMethod( | ||
$this->obTestObject, | ||
'initGlobals' | ||
); | ||
|
||
$this->assertIsArray( | ||
$_GET, | ||
'Суперглобалы не обработались.' | ||
); | ||
|
||
$_GET = $backupGET; | ||
} | ||
|
||
/** | ||
* getRequestUri(). | ||
* | ||
* @return void | ||
*/ | ||
public function testGetRequestUri() : void | ||
{ | ||
$result = $this->obTestObject->getRequestUri(); | ||
|
||
$this->assertSame( | ||
$_SERVER['REQUEST_URI'], | ||
$result, | ||
'Неправильный REQUEST_URI.' | ||
); | ||
} | ||
|
||
/** | ||
* setServer(). | ||
* | ||
* @return void | ||
*/ | ||
public function testSetServer() : void | ||
{ | ||
$key = 'TEST.PHP.UNIT'; | ||
$value = 'OK'; | ||
|
||
$this->obTestObject->setServer($key, $value); | ||
|
||
$request = $this->obTestObject->getRequest(); | ||
|
||
$this->assertSame( | ||
$value, | ||
$request->server->get($key), | ||
'Неправильная установка ключа $_REQUEST.' | ||
); | ||
} | ||
} |
134 changes: 134 additions & 0 deletions
134
tests/Cases/PostLoadingPasses/BootstrapServicesTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
|
||
namespace Prokl\ServiceProvider\Tests\Cases\PostLoadingPasses; | ||
|
||
use Exception; | ||
use Prokl\ServiceProvider\PostLoadingPass\BootstrapServices; | ||
use Prokl\TestingTools\Base\BaseTestCase; | ||
use Symfony\Component\DependencyInjection\Compiler\RemoveUnusedDefinitionsPass; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* Class BootstrapServicesTest | ||
* @package Prokl\ServiceProvider\Tests\Cases\PostLoadingPasses | ||
* @coversDefaultClass BootstrapServices | ||
* | ||
* @since 28.09.2020 | ||
*/ | ||
class BootstrapServicesTest extends BaseTestCase | ||
{ | ||
/** | ||
* @var BootstrapServices $obTestObject Тестируемый объект. | ||
*/ | ||
protected $obTestObject; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->obTestObject = new BootstrapServices(); | ||
} | ||
|
||
/** | ||
* action(). Нормальный ход событий. | ||
* | ||
* @return void | ||
* @throws Exception | ||
*/ | ||
public function testAction(): void | ||
{ | ||
$testContainerBuilder = $this->getTestContainer('service.bootstrap'); | ||
|
||
$result = $this->obTestObject->action( | ||
$testContainerBuilder | ||
); | ||
|
||
$this->assertTrue( | ||
$result, | ||
'Что-то пошло не так.' | ||
); | ||
} | ||
|
||
/** | ||
* action(). Нет обработчиков. Пустой parameterBag. | ||
* | ||
* @return void | ||
* @throws Exception | ||
*/ | ||
public function testActionNoListener(): void | ||
{ | ||
$container = $this->getEmptyContainer(); | ||
|
||
$result = $this->obTestObject->action( | ||
$container | ||
); | ||
|
||
$this->assertFalse( | ||
$result, | ||
'Что-то пошло не так.' | ||
); | ||
} | ||
|
||
/** | ||
* Мок обработчика. | ||
* | ||
* @return mixed | ||
*/ | ||
private function getStubService() | ||
{ | ||
return new class { | ||
public function addEvent(): void | ||
{ | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Тестовый контейнер. | ||
* | ||
* @param string $serviceId ID сервиса. | ||
* @param array $params Параметры. | ||
* | ||
* @return ContainerBuilder | ||
*/ | ||
private function getTestContainer( | ||
string $serviceId, | ||
array $params = [ | ||
['event' => 'test'], | ||
] | ||
): ContainerBuilder { | ||
$container = new ContainerBuilder(); | ||
$container | ||
->register($serviceId, get_class($this->getStubService())) | ||
->setPublic(true); | ||
|
||
$container->setParameter('_bootstrap', [ | ||
$serviceId => $params, | ||
]); | ||
|
||
$this->process($container); | ||
|
||
return $container; | ||
} | ||
|
||
/** | ||
* Пустой контейнер. | ||
* | ||
* @return ContainerBuilder | ||
*/ | ||
private function getEmptyContainer() : ContainerBuilder | ||
{ | ||
return new ContainerBuilder(); | ||
} | ||
|
||
/** | ||
* @param ContainerBuilder $container Контейнер. | ||
*/ | ||
private function process(ContainerBuilder $container): void | ||
{ | ||
(new RemoveUnusedDefinitionsPass())->process($container); | ||
} | ||
} |
Oops, something went wrong.