From dd5d72a994e9df047f48bfd2624e478305fd6fd5 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Tue, 14 Feb 2012 00:28:58 +0100 Subject: [PATCH 1/4] Added Propel to the vendors.php script --- vendors.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vendors.php b/vendors.php index 6434715552..6a29a6f492 100755 --- a/vendors.php +++ b/vendors.php @@ -36,11 +36,12 @@ $deps = array( array('doctrine-dbal', 'http://github.com/doctrine/dbal.git', 'origin/master'), array('doctrine-common', 'http://github.com/doctrine/common.git', 'origin/master'), array('twig', 'http://github.com/fabpot/Twig.git', 'origin/master'), + array('propel', 'http://github.com/propelorm/Propel.git', 'origin/master'), ); foreach ($deps as $dep) { list($name, $url, $rev) = $dep; - + if ($transport) { $url = preg_replace('/^(http:|https:|git:)(.*)/', $transport . ':$2', $url); } From 4878af44ccd42b2e8ca037854786772eeae58e17 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Tue, 14 Feb 2012 00:29:43 +0100 Subject: [PATCH 2/4] [Propel] Fixed CS --- .../Tests/Bridge/Propel1/Form/ChoiceList/ModelChoiceListTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Symfony/Tests/Bridge/Propel1/Form/ChoiceList/ModelChoiceListTest.php b/tests/Symfony/Tests/Bridge/Propel1/Form/ChoiceList/ModelChoiceListTest.php index 20de78d162..c5017a9fbd 100644 --- a/tests/Symfony/Tests/Bridge/Propel1/Form/ChoiceList/ModelChoiceListTest.php +++ b/tests/Symfony/Tests/Bridge/Propel1/Form/ChoiceList/ModelChoiceListTest.php @@ -13,7 +13,6 @@ namespace Symfony\Tests\Bridge\Propel1\Form\ChoiceList; use Symfony\Bridge\Propel1\Form\ChoiceList\ModelChoiceList; use Symfony\Component\Form\Extension\Core\View\ChoiceView; - use Symfony\Tests\Bridge\Propel1\Fixtures\Item; use Symfony\Tests\Bridge\Propel1\Propel1TestCase; From d9ce9825b6b4c3ba5f6e3ab35baaa8f0b1cca5fe Mon Sep 17 00:00:00 2001 From: William DURAND Date: Tue, 14 Feb 2012 00:40:32 +0100 Subject: [PATCH 3/4] [Propel] Added tests for CollectionToArrayTransformer --- .../CollectionToArrayTransformerTest.php | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 tests/Symfony/Tests/Bridge/Propel1/Form/DataTransformer/CollectionToArrayTransformerTest.php diff --git a/tests/Symfony/Tests/Bridge/Propel1/Form/DataTransformer/CollectionToArrayTransformerTest.php b/tests/Symfony/Tests/Bridge/Propel1/Form/DataTransformer/CollectionToArrayTransformerTest.php new file mode 100644 index 0000000000..ea47662d3e --- /dev/null +++ b/tests/Symfony/Tests/Bridge/Propel1/Form/DataTransformer/CollectionToArrayTransformerTest.php @@ -0,0 +1,105 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Tests\Bridge\Propel1\Form\DataTransformer; + +use \PropelCollection; +use Symfony\Bridge\Propel1\Form\DataTransformer\CollectionToArrayTransformer; +use Symfony\Tests\Bridge\Propel1\Propel1TestCase; + +class CollectionToArrayTransformerTest extends Propel1TestCase +{ + private $transformer; + + public function setUp() + { + $this->transformer = new CollectionToArrayTransformer(); + } + + public function testTransform() + { + $result = $this->transformer->transform(new PropelCollection()); + + $this->assertTrue(is_array($result)); + $this->assertEquals(0, count($result)); + } + + public function testTransformWithNull() + { + $result = $this->transformer->transform(null); + + $this->assertTrue(is_array($result)); + $this->assertEquals(0, count($result)); + } + + /** + * @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException + */ + public function testTransformThrowsExceptionIfNotPropelCollection() + { + $this->transformer->transform(new DummyObject()); + } + + public function testTransformWithData() + { + $coll = new PropelCollection(); + $coll->setData(array('foo', 'bar')); + + $result = $this->transformer->transform($coll); + + $this->assertTrue(is_array($result)); + $this->assertEquals(2, count($result)); + $this->assertEquals('foo', $result[0]); + $this->assertEquals('bar', $result[1]); + } + + public function testReverseTransformWithNull() + { + $result = $this->transformer->reverseTransform(null); + + $this->assertInstanceOf('\PropelCollection', $result); + $this->assertEquals(0, count($result->getData())); + } + + public function testReverseTransformWithEmptyString() + { + $result = $this->transformer->reverseTransform(''); + + $this->assertInstanceOf('\PropelCollection', $result); + $this->assertEquals(0, count($result->getData())); + } + + /** + * @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException + */ + public function testReverseTransformThrowsExceptionIfNotArray() + { + $this->transformer->reverseTransform(new DummyObject()); + } + + public function testReverseTransformWithData() + { + $inputData = array('foo', 'bar'); + + $result = $this->transformer->reverseTransform($inputData); + $data = $result->getData(); + + $this->assertInstanceOf('\PropelCollection', $result); + + $this->assertTrue(is_array($data)); + $this->assertEquals(2, count($data)); + $this->assertEquals('foo', $data[0]); + $this->assertEquals('bar', $data[1]); + $this->assertsame($inputData, $data); + } +} + +class DummyObject {} From 97cbf900cc1bc586f4af9cbfc6c0f8309f0e5d43 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Tue, 14 Feb 2012 00:59:48 +0100 Subject: [PATCH 4/4] [Propel] Added tests for the PropelDataCollector --- .../DataCollector/PropelDataCollectorTest.php | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 tests/Symfony/Tests/Bridge/Propel1/DataCollector/PropelDataCollectorTest.php diff --git a/tests/Symfony/Tests/Bridge/Propel1/DataCollector/PropelDataCollectorTest.php b/tests/Symfony/Tests/Bridge/Propel1/DataCollector/PropelDataCollectorTest.php new file mode 100644 index 0000000000..9f7c094eb8 --- /dev/null +++ b/tests/Symfony/Tests/Bridge/Propel1/DataCollector/PropelDataCollectorTest.php @@ -0,0 +1,92 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Tests\Bridge\Propel1\DataCollector; + +use Symfony\Bridge\Propel1\DataCollector\PropelDataCollector; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Tests\Bridge\Propel1\Propel1TestCase; + +class PropelDataCollectorTest extends Propel1TestCase +{ + public function testCollectWithoutData() + { + $c = $this->createCollector(array()); + $c->collect(new Request(), new Response()); + + $this->assertEquals(array(), $c->getQueries()); + $this->assertEquals(0, $c->getQueryCount()); + } + + public function testCollectWithData() + { + $queries = array( + "time: 0.000 sec | mem: 1.4 MB | SET NAMES 'utf8'", + ); + + $c = $this->createCollector($queries); + $c->collect(new Request(), new Response()); + + $this->assertEquals(array( + array( + 'sql' => "SET NAMES 'utf8'", + 'time' => '0.000 sec', + 'memory' => '1.4 MB' + ) + ), $c->getQueries()); + $this->assertEquals(1, $c->getQueryCount()); + } + + public function testCollectWithMultipleData() + { + $queries = array( + "time: 0.000 sec | mem: 1.4 MB | SET NAMES 'utf8'", + "time: 0.012 sec | mem: 2.4 MB | SELECT tags.NAME, image.FILENAME FROM tags LEFT JOIN image ON tags.IMAGEID = image.ID WHERE image.ID = 12" + ); + + $c = $this->createCollector($queries); + $c->collect(new Request(), new Response()); + + $this->assertEquals(array( + array( + 'sql' => "SET NAMES 'utf8'", + 'time' => '0.000 sec', + 'memory' => '1.4 MB' + ), + array( + 'sql' => "SELECT tags.NAME, image.FILENAME FROM tags LEFT JOIN image ON tags.IMAGEID = image.ID WHERE image.ID = 12", + 'time' => '0.012 sec', + 'memory' => '2.4 MB' + ) + ), $c->getQueries()); + $this->assertEquals(2, $c->getQueryCount()); + } + + private function createCollector($queries) + { + $config = $this->getMock('\PropelConfiguration'); + $config + ->expects($this->any()) + ->method('getParameter') + ->will($this->returnArgument(1)) + ; + + $logger = $this->getMock('\Symfony\Bridge\Propel1\Logger\PropelLogger'); + $logger + ->expects($this->any()) + ->method('getQueries') + ->will($this->returnValue($queries)) + ; + + return new PropelDataCollector($logger, $config); + } +}