Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhard-efler committed Apr 20, 2021
1 parent b8a1286 commit b554772
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/Console/ConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@ public function __construct(string $bootstrapDirectory, string $applicationCache
{
$this->bootstrapDirectory = $bootstrapDirectory;
$this->applicationCacheDirectory = $applicationCacheDirectory;
}

/**
* @throws \Exception
* @codeCoverageIgnore
*/
public function run(): void
{
//TODO make a proper short syntax check (for grouped input options)
if (isset($_SERVER['argv']) &&
\is_array($_SERVER['argv']) &&
(\array_search('-d', $_SERVER['argv'], true) !== false || \array_search('--development', $_SERVER['argv'], true) !== false)
) {
$this->isDevelopment = true;
}
}

/**
* @throws \Exception
* @codeCoverageIgnore
*/
public function run(): void
{
$serviceManager = (new ApplicationBootstrap())->bootstrap(
$this->bootstrapDirectory,
$this->applicationCacheDirectory,
Expand Down
11 changes: 6 additions & 5 deletions tests/src/ApplicationBootstrapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,20 @@ protected function tearDown(): void

protected function setUp(): void
{
$this->vfsCache = vfsStream::setup('cache');
$this->vfsCache = vfsStream::setup('data');
}

public function testMinimalBootstrap()
{
$application = $this->createMock(ApplicationInterface::class);

$vfsBootstrap = vfsStream::setup('bootstrap');
\mkdir($this->vfsCache->url() . '/bootstrap');
\mkdir($this->vfsCache->url() . '/cache');

$bootstrap = new ApplicationBootstrap();
$serviceManager = $bootstrap->bootstrap($vfsBootstrap->url(), $this->vfsCache->url(), $application, new BootstrapFactory());
$serviceManager = $bootstrap->bootstrap($this->vfsCache->url() . '/bootstrap', $this->vfsCache->url() . '/cache/', $application, new BootstrapFactory());

$this->assertFalse($this->vfsCache->hasChildren());
$this->assertTrue($this->vfsCache->getChild('cache')->hasChildren());

$this->assertInstanceOf(ServiceManager::class, $serviceManager);
$this->assertInstanceOf(ApplicationConfig::class, $serviceManager->get(ApplicationConfig::class));
Expand Down Expand Up @@ -125,7 +126,7 @@ public function testPackageBoot()
$bootstrap = new ApplicationBootstrap();
$serviceManager = $bootstrap->bootstrap(
$vfsBootstrap->url() . '/',
$this->vfsCache->url() . '/',
$vfsBootstrap->url() . '/',
$application,
$bootstrapFactoryMock
);
Expand Down
9 changes: 5 additions & 4 deletions tests/src/Console/ConsoleApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ class ConsoleApplicationTest extends TestCase
{
public function testConfigure()
{
$application = new ConsoleApplication('/bootstrap');

$_SERVER['argv'] = ['-d'];
$configurator = $this->createMock(ApplicationConfigurator::class);
$configurator->expects($this->once())
->method('setDevelopment')
->willReturnCallback(function ($param) {
$this->assertTrue($param);
});
$application = new ConsoleApplication('/bootstrap');
$application->configure($configurator);

$_SERVER['argv'] = ['--development'];
Expand All @@ -35,29 +34,31 @@ public function testConfigure()
->willReturnCallback(function ($param) {
$this->assertTrue($param);
});
$application = new ConsoleApplication('/bootstrap');
$application->configure($configurator);
}

public function testEmptyConfigure()
{
$application = new ConsoleApplication('/bootstrap');

unset($_SERVER['argv']);
$configurator = $this->createMock(ApplicationConfigurator::class);
$configurator->expects($this->never())
->method('setDevelopment');
$application = new ConsoleApplication('/bootstrap');
$application->configure($configurator);

$_SERVER['argv'] = 'string';
$configurator = $this->createMock(ApplicationConfigurator::class);
$configurator->expects($this->never())
->method('setDevelopment');
$application = new ConsoleApplication('/bootstrap');
$application->configure($configurator);

$_SERVER['argv'] = ['string'];
$configurator = $this->createMock(ApplicationConfigurator::class);
$configurator->expects($this->never())
->method('setDevelopment');
$application = new ConsoleApplication('/bootstrap');
$application->configure($configurator);
}
}

0 comments on commit b554772

Please sign in to comment.