-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update unit tests for dispatching models (#56)
- Loading branch information
Showing
7 changed files
with
340 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,17 +10,18 @@ | |
{ "name": "Pierre Ducoudray", "email": "[email protected]" } | ||
], | ||
"require": { | ||
"php": ">=5.3.3", | ||
"ext-curl": "*", | ||
"guzzle/guzzle": "~3.7" | ||
"php": ">=5.3.3", | ||
"ext-curl": "*", | ||
"guzzle/guzzle": "~3.7" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "~4.0", | ||
"fabpot/php-cs-fixer": "^1.11", | ||
"pagerfanta/pagerfanta": "^1.0", | ||
"symfony/http-foundation": "^2.7", | ||
"sylius/resource": "@dev", | ||
"doctrine/orm": "^2.3" | ||
"phpunit/phpunit": "~4.0", | ||
"fabpot/php-cs-fixer": "^1.11", | ||
"pagerfanta/pagerfanta": "^1.0", | ||
"symfony/http-foundation": "^2.7", | ||
"sylius/resource": "@dev", | ||
"doctrine/orm": "^2.3", | ||
"gedmo/doctrine-extensions": "^2.4" | ||
}, | ||
"suggest": { | ||
"symfony/http-foundation": "To use the callback handler", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
test/Textmaster/Tests/Translator/Adapter/GedmoTranslatableAdapterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
namespace Textmaster\Tests\Translator\Adapter; | ||
|
||
use Textmaster\Translator\Adapter\GedmoTranslatableAdapter; | ||
|
||
class GedmoTranslatableAdapterTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldCreateSameLocale() | ||
{ | ||
$managerRegistryMock = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry'); | ||
$listenerMock = $this->getMock('Gedmo\Translatable\TranslatableListener'); | ||
|
||
$translatableMock = $this->getMock('Gedmo\Translatable\Translatable', array('getName', 'getId')); | ||
$documentMock = $this->getMock('Textmaster\Model\Document', array('getProject', 'save'), array(), '', false); | ||
$projectMock = $this->getMock('Textmaster\Model\Project', array('getLanguageFrom'), array(), '', false); | ||
|
||
$translatableMock->expects($this->once()) | ||
->method('getName') | ||
->willReturn('name'); | ||
$translatableMock->expects($this->once()) | ||
->method('getId') | ||
->willReturn(1); | ||
|
||
$documentMock->expects($this->once()) | ||
->method('getProject') | ||
->willReturn($projectMock); | ||
$documentMock->expects($this->once()) | ||
->method('save') | ||
->willReturn($documentMock); | ||
|
||
$projectMock->expects($this->once()) | ||
->method('getLanguageFrom') | ||
->willReturn('en'); | ||
|
||
$listenerMock->expects($this->once()) | ||
->method('getListenerLocale') | ||
->willReturn('en'); | ||
|
||
$adapter = new GedmoTranslatableAdapter($managerRegistryMock, $listenerMock); | ||
$adapter->create($translatableMock, array('name'), $documentMock); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldCreateDifferentLocale() | ||
{ | ||
$managerRegistryMock = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry'); | ||
$listenerMock = $this->getMock('Gedmo\Translatable\TranslatableListener'); | ||
|
||
$translatableMock = $this->getMock('Gedmo\Translatable\Translatable', array('setLocale', 'getName', 'getId')); | ||
$documentMock = $this->getMock('Textmaster\Model\Document', array('getProject', 'save'), array(), '', false); | ||
$projectMock = $this->getMock('Textmaster\Model\Project', array('getLanguageFrom'), array(), '', false); | ||
$entityManagerMock = $this->getMock('Doctrine\Common\Persistence\ObjectManager'); | ||
|
||
$translatableMock->expects($this->once()) | ||
->method('getName') | ||
->willReturn('name'); | ||
$translatableMock->expects($this->once()) | ||
->method('getId') | ||
->willReturn(1); | ||
|
||
$documentMock->expects($this->once()) | ||
->method('getProject') | ||
->willReturn($projectMock); | ||
$documentMock->expects($this->once()) | ||
->method('save') | ||
->willReturn($documentMock); | ||
|
||
$projectMock->expects($this->once()) | ||
->method('getLanguageFrom') | ||
->willReturn('en'); | ||
|
||
$listenerMock->expects($this->once()) | ||
->method('getListenerLocale') | ||
->willReturn('fr'); | ||
|
||
$managerRegistryMock->expects($this->once()) | ||
->method('getManagerForClass') | ||
->willReturn($entityManagerMock); | ||
|
||
$entityManagerMock->expects($this->once()) | ||
->method('refresh'); | ||
|
||
$adapter = new GedmoTranslatableAdapter($managerRegistryMock, $listenerMock); | ||
$adapter->create($translatableMock, array('name'), $documentMock); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
test/Textmaster/Tests/Translator/Provider/ChainedMappingProviderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Textmaster\Tests\Translator\Provider; | ||
|
||
use Textmaster\Exception\MappingNotFoundException; | ||
use Textmaster\Tests\Mock\MockTranslatable; | ||
use Textmaster\Translator\Provider\ChainedMappingProvider; | ||
|
||
class ChainedMappingProviderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldGetProperties() | ||
{ | ||
$providerMock1 = $this->getMock('Textmaster\Translator\Provider\MappingProviderInterface'); | ||
$providerMock2 = $this->getMock('Textmaster\Translator\Provider\MappingProviderInterface'); | ||
$providers = array($providerMock1, $providerMock2); | ||
|
||
$subjectMock = new MockTranslatable(); | ||
|
||
$providerMock1->expects($this->once()) | ||
->method('getProperties') | ||
->will($this->throwException(new MappingNotFoundException('value'))); | ||
|
||
$providerMock2->expects($this->once()) | ||
->method('getProperties') | ||
->willReturn(array('name')); | ||
|
||
$provider = new ChainedMappingProvider($providers); | ||
$properties = $provider->getProperties($subjectMock); | ||
|
||
$this->assertSame(array('name'), $properties); | ||
} | ||
|
||
/** | ||
* @test | ||
* @expectedException \Textmaster\Exception\MappingNotFoundException | ||
*/ | ||
public function shouldNotGetProperties() | ||
{ | ||
$providerMock1 = $this->getMock('Textmaster\Translator\Provider\MappingProviderInterface'); | ||
$providerMock2 = $this->getMock('Textmaster\Translator\Provider\MappingProviderInterface'); | ||
$providers = array($providerMock1, $providerMock2); | ||
|
||
$subjectMock = new MockTranslatable(); | ||
|
||
$providerMock1->expects($this->once()) | ||
->method('getProperties') | ||
->will($this->throwException(new MappingNotFoundException('value'))); | ||
|
||
$providerMock2->expects($this->once()) | ||
->method('getProperties') | ||
->will($this->throwException(new MappingNotFoundException('value'))); | ||
|
||
$provider = new ChainedMappingProvider($providers); | ||
$provider->getProperties($subjectMock); | ||
} | ||
} |
Oops, something went wrong.