merged branch willdurand/propel-tests (PR #3348)
Commits -------97cbf90
[Propel] Added tests for the PropelDataCollectord9ce982
[Propel] Added tests for CollectionToArrayTransformer4878af4
[Propel] Fixed CSdd5d72a
Added Propel to the vendors.php script Discussion ---------- Propel tests This PR adds more unit tests on the Propel Bridge. More to come later :)
This commit is contained in:
commit
4ed094c965
@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
}
|
@ -13,7 +13,6 @@ namespace Symfony\Tests\Bridge\Propel1\Form\ChoiceList;
|
|||||||
|
|
||||||
use Symfony\Bridge\Propel1\Form\ChoiceList\ModelChoiceList;
|
use Symfony\Bridge\Propel1\Form\ChoiceList\ModelChoiceList;
|
||||||
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
|
|
||||||
use Symfony\Tests\Bridge\Propel1\Fixtures\Item;
|
use Symfony\Tests\Bridge\Propel1\Fixtures\Item;
|
||||||
use Symfony\Tests\Bridge\Propel1\Propel1TestCase;
|
use Symfony\Tests\Bridge\Propel1\Propel1TestCase;
|
||||||
|
|
||||||
|
@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* 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 {}
|
@ -36,11 +36,12 @@ $deps = array(
|
|||||||
array('doctrine-dbal', 'http://github.com/doctrine/dbal.git', 'origin/master'),
|
array('doctrine-dbal', 'http://github.com/doctrine/dbal.git', 'origin/master'),
|
||||||
array('doctrine-common', 'http://github.com/doctrine/common.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('twig', 'http://github.com/fabpot/Twig.git', 'origin/master'),
|
||||||
|
array('propel', 'http://github.com/propelorm/Propel.git', 'origin/master'),
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($deps as $dep) {
|
foreach ($deps as $dep) {
|
||||||
list($name, $url, $rev) = $dep;
|
list($name, $url, $rev) = $dep;
|
||||||
|
|
||||||
if ($transport) {
|
if ($transport) {
|
||||||
$url = preg_replace('/^(http:|https:|git:)(.*)/', $transport . ':$2', $url);
|
$url = preg_replace('/^(http:|https:|git:)(.*)/', $transport . ':$2', $url);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user