propel-bundle/Tests/Service/SchemaLocatorTest.php
Drew Brown ea6a359272 Symfony 4.0 updates (#483)
* Upd: Add Symfony 4 Compatibility

#SymfonyConHackday2017

* Upd: Configure visibility of services for SF4

* Updated composer to allow Symfony 4.0

* Updated composer to allow Symfony 4.0

* PropelBundle for Symfony 4

* Upd: Travis configuration

* Upd: PHP 5 not supported anymore by PHPUnit

* Upd: Removing old SF version + PHPUnit correction

* * Removed param that was removed in symfony/yaml afb873f
* Updated format of object dumping as deprecated tags using colon symfony/yaml 38d3087

* * Added commands to console.xml as symfony no longer auto registers bundle commands
* Updated two services to public

* * Removed deprecated getMock calls for new createMock calls.

* * Add stub for additional abstract method

* * Updated schema locator test
* reverted unnecessary changes to abstract command and schemal locator
* Added fixtures for schema testing.

* * Updated schema locator test
* reverted unnecessary changes to abstract command and schemal locator
* Added fixtures for schema testing.

* * Removed unnecessary default for services
* Updated readme to reflect symfony version support
2018-02-10 01:25:14 +01:00

98 lines
3 KiB
PHP

<?php
/**
* This file is part of the PropelBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
namespace Propel\Bundle\PropelBundle\Tests\Service;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
use PHPUnit\Framework\MockObject\MockObject;
use Propel\Bundle\PropelBundle\Service\SchemaLocator;
use Propel\Bundle\PropelBundle\Tests\Fixtures\FakeBundle\FakeBundle;
use Propel\Bundle\PropelBundle\Tests\TestCase;
use Propel\Common\Config\FileLocator;
use Symfony\Component\HttpKernel\Kernel;
class SchemaLocatorTest extends TestCase
{
/**
* @var Kernel
*/
private $kernelMock;
/**
* @var vfsStreamDirectory
*/
private $root;
/**
* @var array
*/
private $configuration;
private $fileLocator;
/**
* @var MockObject
*/
private $bundleMock;
public function setUp()
{
$pathStructure = [
'configuration' => [
'directory' => [
'schema.xml' => 'Schema from configuration'
]
],
];
$this->root = vfsStream::setup('projectDir');
vfsStream::create($pathStructure);
$this->kernelMock = $this->getMockBuilder(Kernel::class)->disableOriginalConstructor()-> getMock();
$this->kernelMock->method('getProjectDir')->willReturn($this->root->url());
$this->bundleMock = new FakeBundle();
$this->configuration['paths']['schemaDir'] = vfsStream::url('projectDir/configuration/directory');
$this->fileLocator = new FileLocator(
[
__DIR__ . '/../Fixtures',
]
);
}
public function testLocateFromBundle()
{
$locator = new SchemaLocator($this->fileLocator, $this->configuration);
$files = $locator->locateFromBundle($this->bundleMock);
$this->assertCount(1, $files);
$this->assertTrue(isset($files[__DIR__ . '/../Fixtures/FakeBundle/Resources/config/bundle.schema.xml']));
$this->assertEquals('bundle.schema.xml', $files[__DIR__ . '/../Fixtures/FakeBundle/Resources/config/bundle.schema.xml'][1]->getFileName());
}
public function testLocateFromBundlesAndConfiguration()
{
$locator = new SchemaLocator($this->fileLocator, $this->configuration);
$files = $locator->locateFromBundlesAndConfiguration(
[$this->bundleMock]
);
$this->assertCount(2, $files);
$this->assertTrue(isset($files[__DIR__ . '/../Fixtures/FakeBundle/Resources/config/bundle.schema.xml']));
$this->assertEquals('bundle.schema.xml', $files[__DIR__ . '/../Fixtures/FakeBundle/Resources/config/bundle.schema.xml'][1]->getFileName());
$this->assertTrue(isset($files['vfs://projectDir/configuration/directory/schema.xml']));
$this->assertEquals('schema.xml', $files['vfs://projectDir/configuration/directory/schema.xml'][1]->getFileName());
}
}