Skip to content

Commit

Permalink
Improved ModelToIdTransformerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
pulzarraider committed Sep 14, 2013
1 parent ff23eda commit 30d44b0
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions Tests/Form/DataTransformer/ModelToIdTransformerTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* This file is part of the Sonata package.
*
Expand All @@ -24,17 +25,16 @@ public function setUp()
public function testReverseTransformWhenPassing0AsId()
{
$transformer = new ModelToIdTransformer($this->modelManager,'TEST');



$this->modelManager
->expects($this->exactly(2))
->method('find');

//we pass 0 as integer
// this must call the model manager find method... i not care what is returned, but must be called
$transformer->reverseTransform(0);
//we pass 0 as string

//we pass 0 as string
//this must call the model manager find method... i not care what is returned, but must be called
$transformer->reverseTransform('0');

Expand All @@ -44,4 +44,20 @@ public function testReverseTransformWhenPassing0AsId()
//we pass false, must return null
$this->assertNull($transformer->reverseTransform(false));
}

public function testTransform()
{
$this->modelManager->expects($this->once())
->method('getIdentifierValues')
->will($this->returnValue(array(123)));

$transformer = new ModelToIdTransformer($this->modelManager,'TEST');

$this->assertNull($transformer->transform(null));
$this->assertNull($transformer->transform(false));
$this->assertNull($transformer->transform(0));
$this->assertNull($transformer->transform('0'));

$this->assertEquals(123, $transformer->transform(new \stdClass));
}
}

0 comments on commit 30d44b0

Please sign in to comment.