Added few unit tests, fixed CS
This commit is contained in:
parent
ef891c953e
commit
dd13a0f40b
|
@ -63,7 +63,7 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
static public function getPackagePrefix(Bundle $bundle, $baseDirectory = '')
|
||||
protected function getPackagePrefix(Bundle $bundle, $baseDirectory = '')
|
||||
{
|
||||
$parts = explode(DIRECTORY_SEPARATOR, realpath($bundle->getPath()));
|
||||
$length = count(explode('\\', $bundle->getNamespace())) * (-1);
|
||||
|
@ -192,7 +192,7 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
|
|||
$finalSchemas = $this->getFinalSchemas($kernel, $this->bundle);
|
||||
foreach ($finalSchemas as $schema) {
|
||||
list($bundle, $finalSchema) = $schema;
|
||||
$packagePrefix = self::getPackagePrefix($bundle, $base);
|
||||
$packagePrefix = $this->getPackagePrefix($bundle, $base);
|
||||
|
||||
$tempSchema = $bundle->getName().'-'.$finalSchema->getBaseName();
|
||||
$this->tempSchemas[$tempSchema] = array(
|
||||
|
@ -281,6 +281,10 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
|
|||
return $finalSchemas;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \SplFileInfo $file
|
||||
* @return string
|
||||
*/
|
||||
protected function getRelativeFileName(\SplFileInfo $file)
|
||||
{
|
||||
return substr(str_replace(realpath($this->getContainer()->getParameter('kernel.root_dir') . '/../'), '', $file), 1);
|
||||
|
@ -403,6 +407,14 @@ EOT;
|
|||
return $this->cacheDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\Config\FileLocatorInterface
|
||||
*/
|
||||
protected function getFileLocator()
|
||||
{
|
||||
return $this->getContainer()->get('file_locator');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get connection by checking the input option named 'connection'.
|
||||
* Returns the default connection if no option specified or an exception
|
||||
|
@ -521,18 +533,18 @@ EOT;
|
|||
* @param OutputInterface $output The output.
|
||||
* @param string $filename The filename.
|
||||
*/
|
||||
protected function writeNewFile($output, $filename)
|
||||
protected function writeNewFile(OutputInterface $output, $filename)
|
||||
{
|
||||
return $output->writeln('>> <info>File+</info> ' . $filename);
|
||||
$output->writeln('>> <info>File+</info> ' . $filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OutputInterface $output The output.
|
||||
* @param string $directory The directory.
|
||||
*/
|
||||
protected function writeNewDirectory($output, $directory)
|
||||
protected function writeNewDirectory(OutputInterface $output, $directory)
|
||||
{
|
||||
return $output->writeln('>> <info>Dir+</info> ' . $directory);
|
||||
$output->writeln('>> <info>Dir+</info> ' . $directory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -548,14 +560,11 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\Config\FileLocatorInterface
|
||||
* @param \SplFileInfo $schema
|
||||
* @param BundleInterface $bundle
|
||||
* @return string
|
||||
*/
|
||||
protected function getFileLocator()
|
||||
{
|
||||
return $this->getContainer()->get('file_locator');
|
||||
}
|
||||
|
||||
private function transformToLogicalName(\SplFileInfo $schema, BundleInterface $bundle)
|
||||
protected function transformToLogicalName(\SplFileInfo $schema, BundleInterface $bundle)
|
||||
{
|
||||
$schemaPath = str_replace(
|
||||
$bundle->getPath(). DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR,
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
namespace Propel\PropelBundle\Command;
|
||||
|
||||
require_once 'phing/Phing.php';
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
|
|
|
@ -75,10 +75,12 @@ class PanelController extends ContainerAware
|
|||
return new Response('<div class="error">This query cannot be explained.</div>');
|
||||
}
|
||||
|
||||
return $this->container->get('templating')->renderResponse('PropelBundle:Panel:explain.html.twig', array(
|
||||
'data' => $results,
|
||||
'query' => $query,
|
||||
));
|
||||
|
||||
return $this->container->get('templating')->renderResponse(
|
||||
'PropelBundle:Panel:explain.html.twig',
|
||||
array(
|
||||
'data' => $results,
|
||||
'query' => $query,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,9 @@ namespace Propel\PropelBundle\Tests\Command;
|
|||
|
||||
use Propel\PropelBundle\Tests\TestCase;
|
||||
use Propel\PropelBundle\Command\AbstractPropelCommand;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
/**
|
||||
* @author William Durand <william.durand1@gmail.com>
|
||||
|
@ -35,12 +38,232 @@ class AbstractPropelCommandTest extends TestCase
|
|||
{
|
||||
$this->assertNull($this->command->parseDbName('foo'));
|
||||
}
|
||||
|
||||
public function testTransformToLogicalName()
|
||||
{
|
||||
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
|
||||
$bundle
|
||||
->expects($this->once())
|
||||
->method('getName')
|
||||
->will($this->returnValue('MySuperBundle'));
|
||||
$bundle
|
||||
->expects($this->once())
|
||||
->method('getPath')
|
||||
->will($this->returnValue('/Users/foo/project/src/My/SuperBundle'));
|
||||
|
||||
$schema = $this
|
||||
->getMockBuilder('\SplFileInfo')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$schema
|
||||
->expects($this->once())
|
||||
->method('getRealPath')
|
||||
->will($this->returnValue('/Users/foo/project/src/My/SuperBundle/Resources/config/my-schema.xml'));
|
||||
|
||||
$expected = '@MySuperBundle/Resources/config/my-schema.xml';
|
||||
|
||||
$this->assertEquals($expected, $this->command->transformToLogicalName($schema, $bundle));
|
||||
}
|
||||
|
||||
public function testTransformToLogicalNameWithSubDir()
|
||||
{
|
||||
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
|
||||
$bundle
|
||||
->expects($this->once())
|
||||
->method('getName')
|
||||
->will($this->returnValue('MySuperBundle'));
|
||||
$bundle
|
||||
->expects($this->once())
|
||||
->method('getPath')
|
||||
->will($this->returnValue('/Users/foo/project/src/My/SuperBundle'));
|
||||
|
||||
$schema = $this
|
||||
->getMockBuilder('\SplFileInfo')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$schema
|
||||
->expects($this->once())
|
||||
->method('getRealPath')
|
||||
->will($this->returnValue('/Users/foo/project/src/My/SuperBundle/Resources/config/propel/my-schema.xml'));
|
||||
|
||||
$expected = '@MySuperBundle/Resources/config/propel/my-schema.xml';
|
||||
|
||||
$this->assertEquals($expected, $this->command->transformToLogicalName($schema, $bundle));
|
||||
}
|
||||
|
||||
public function testGetSchemasFromBundle()
|
||||
{
|
||||
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
|
||||
$bundle
|
||||
->expects($this->once())
|
||||
->method('getName')
|
||||
->will($this->returnValue('MySuperBundle'));
|
||||
$bundle
|
||||
->expects($this->exactly(2))
|
||||
->method('getPath')
|
||||
->will($this->returnValue(__DIR__ . '/../Fixtures/src/My/SuperBundle'));
|
||||
|
||||
$aSchema = realpath(__DIR__ . '/../Fixtures/src/My/SuperBundle/Resources/config/a-schema.xml');
|
||||
|
||||
// hack to by pass the file locator
|
||||
$this->command->setLocateResponse($aSchema);
|
||||
|
||||
$schemas = $this->command->getSchemasFromBundle($bundle);
|
||||
|
||||
$this->assertNotNull($schemas);
|
||||
$this->assertTrue(is_array($schemas));
|
||||
$this->assertCount(1, $schemas);
|
||||
$this->assertArrayHasKey($aSchema, $schemas);
|
||||
$this->assertSame($bundle, $schemas[$aSchema][0]);
|
||||
$this->assertEquals(new \SplFileInfo($aSchema), $schemas[$aSchema][1]);
|
||||
}
|
||||
|
||||
public function testGetSchemasFromBundleWithNoSchema()
|
||||
{
|
||||
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
|
||||
$bundle
|
||||
->expects($this->once())
|
||||
->method('getPath')
|
||||
->will($this->returnValue(__DIR__ . '/../Fixtures/src/My/SecondBundle'));
|
||||
|
||||
$schemas = $this->command->getSchemasFromBundle($bundle);
|
||||
|
||||
$this->assertNotNull($schemas);
|
||||
$this->assertTrue(is_array($schemas));
|
||||
$this->assertCount(0, $schemas);
|
||||
}
|
||||
|
||||
public function testGetFinalSchemasWithNoSchemaInBundles()
|
||||
{
|
||||
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
|
||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
|
||||
|
||||
$bundle
|
||||
->expects($this->once())
|
||||
->method('getPath')
|
||||
->will($this->returnValue(__DIR__ . '/../Fixtures/src/My/SecondBundle'));
|
||||
|
||||
$kernel
|
||||
->expects($this->once())
|
||||
->method('getBundles')
|
||||
->will($this->returnValue(array($bundle)));
|
||||
|
||||
$schemas = $this->command->getFinalSchemas($kernel);
|
||||
|
||||
$this->assertNotNull($schemas);
|
||||
$this->assertTrue(is_array($schemas));
|
||||
$this->assertCount(0, $schemas);
|
||||
}
|
||||
|
||||
public function testGetFinalSchemas()
|
||||
{
|
||||
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
|
||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
|
||||
|
||||
$bundle
|
||||
->expects($this->once())
|
||||
->method('getName')
|
||||
->will($this->returnValue('MySuperBundle'));
|
||||
$bundle
|
||||
->expects($this->exactly(2))
|
||||
->method('getPath')
|
||||
->will($this->returnValue(__DIR__ . '/../Fixtures/src/My/SuperBundle'));
|
||||
|
||||
$aSchema = realpath(__DIR__ . '/../Fixtures/src/My/SuperBundle/Resources/config/a-schema.xml');
|
||||
|
||||
// hack to by pass the file locator
|
||||
$this->command->setLocateResponse($aSchema);
|
||||
|
||||
$kernel
|
||||
->expects($this->once())
|
||||
->method('getBundles')
|
||||
->will($this->returnValue(array($bundle)));
|
||||
|
||||
$schemas = $this->command->getFinalSchemas($kernel);
|
||||
|
||||
$this->assertNotNull($schemas);
|
||||
$this->assertTrue(is_array($schemas));
|
||||
$this->assertCount(1, $schemas);
|
||||
$this->assertArrayHasKey($aSchema, $schemas);
|
||||
$this->assertSame($bundle, $schemas[$aSchema][0]);
|
||||
$this->assertEquals(new \SplFileInfo($aSchema), $schemas[$aSchema][1]);
|
||||
}
|
||||
|
||||
public function testGetFinalSchemasWithGivenBundle()
|
||||
{
|
||||
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
|
||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
|
||||
|
||||
$bundle
|
||||
->expects($this->once())
|
||||
->method('getName')
|
||||
->will($this->returnValue('MySuperBundle'));
|
||||
$bundle
|
||||
->expects($this->exactly(2))
|
||||
->method('getPath')
|
||||
->will($this->returnValue(__DIR__ . '/../Fixtures/src/My/SuperBundle'));
|
||||
|
||||
$aSchema = realpath(__DIR__ . '/../Fixtures/src/My/SuperBundle/Resources/config/a-schema.xml');
|
||||
|
||||
// hack to by pass the file locator
|
||||
$this->command->setLocateResponse($aSchema);
|
||||
|
||||
$kernel
|
||||
->expects($this->never())
|
||||
->method('getBundles');
|
||||
|
||||
$schemas = $this->command->getFinalSchemas($kernel, $bundle);
|
||||
|
||||
$this->assertNotNull($schemas);
|
||||
$this->assertTrue(is_array($schemas));
|
||||
$this->assertCount(1, $schemas);
|
||||
$this->assertArrayHasKey($aSchema, $schemas);
|
||||
$this->assertSame($bundle, $schemas[$aSchema][0]);
|
||||
$this->assertEquals(new \SplFileInfo($aSchema), $schemas[$aSchema][1]);
|
||||
}
|
||||
}
|
||||
|
||||
class TestableAbstractPropelCommand extends AbstractPropelCommand
|
||||
{
|
||||
private $locate;
|
||||
|
||||
public function setLocateResponse($locate)
|
||||
{
|
||||
$this->locate = $locate;
|
||||
}
|
||||
|
||||
public function getContainer()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get($service)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function locate($file)
|
||||
{
|
||||
return $this->locate;
|
||||
}
|
||||
|
||||
public function parseDbName($dsn)
|
||||
{
|
||||
return parent::parseDbName($dsn);
|
||||
}
|
||||
|
||||
public function transformToLogicalName(\SplFileInfo $schema, BundleInterface $bundle)
|
||||
{
|
||||
return parent::transformToLogicalName($schema, $bundle);
|
||||
}
|
||||
|
||||
public function getSchemasFromBundle(BundleInterface $bundle)
|
||||
{
|
||||
return parent::getSchemasFromBundle($bundle);
|
||||
}
|
||||
|
||||
public function getFinalSchemas(KernelInterface $kernel, BundleInterface $bundle = null)
|
||||
{
|
||||
return parent::getFinalSchemas($kernel, $bundle);
|
||||
}
|
||||
}
|
||||
|
|
0
Tests/Fixtures/src/My/SecondBundle/Resources/config
Normal file
0
Tests/Fixtures/src/My/SecondBundle/Resources/config
Normal file
|
@ -0,0 +1 @@
|
|||
This is a schema.xml
|
Loading…
Reference in a new issue