-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHPUnit: Updated and fixed all unit tests
- Loading branch information
Showing
7 changed files
with
155 additions
and
80 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
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 Intracto\SmartCodeBundle\Tests\Generator; | ||
|
||
use Intracto\SmartCodeBundle\Action\SmartCodeAction; | ||
use Intracto\SmartCodeBundle\Entity\SmartCode; | ||
use Intracto\SmartCodeBundle\Generator\SmartCodeGenerator; | ||
use Intracto\SmartCodeBundle\Generator\SmartCodeOptions; | ||
use Intracto\SmartCodeBundle\Tests\BaseTest; | ||
|
||
class SmartCodeActionTest extends BaseTest | ||
{ | ||
private $action; | ||
private $generator; | ||
private $subject; | ||
private $code; | ||
|
||
/** | ||
* @return null | ||
*/ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->action = new SmartCodeAction($this->entityManager); | ||
$this->generator = new SmartCodeGenerator($this->entityManager); | ||
$this->subject = $this->getMock('Intracto\SmartCodeBundle\Entity\SubjectInterface'); | ||
|
||
$payload = $this->getMock('Intracto\SmartCodeBundle\Entity\PayloadInterface'); | ||
$options = new SmartCodeOptions(); | ||
$options->setAmount(1); | ||
$codes = $this->generator->generate($payload, $options); | ||
$this->code = $codes[0]; | ||
} | ||
|
||
public function testGenerator() | ||
{ | ||
$this->assertInstanceOf('Intracto\SmartCodeBundle\Action\SmartCodeActionInterface', $this->action); | ||
} | ||
|
||
public function testRegister() | ||
{ | ||
$this->assertTrue($this->code->isValid()); | ||
|
||
$this->action->register($this->subject, $this->code); | ||
|
||
$this->assertFalse($this->code->isValid()); | ||
} | ||
|
||
public function testUnregister() | ||
{ | ||
$this->action->register($this->subject, $this->code); | ||
|
||
$this->assertFalse($this->code->isValid()); | ||
|
||
$this->action->unregister($this->subject, $this->code); | ||
|
||
$this->assertTrue($this->code->isValid()); | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
namespace Intracto\SmartCodeBundle\Tests; | ||
|
||
/** | ||
* Test case class helpful with Entity tests requiring the database interaction. | ||
* For regular entity tests it's better to extend standard \PHPUnit_Framework_TestCase instead. | ||
*/ | ||
abstract class BaseTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
protected $entityManager; | ||
|
||
/** | ||
* @return null | ||
*/ | ||
public function setUp() | ||
{ | ||
$this->entityManager = $this->createLoadedMockedDoctrineRepository('AppBundle', 'SmartCodeBundle:SmartCode', 'findOneBy', null); | ||
parent::setUp(); | ||
} | ||
|
||
protected function createLoadedMockedDoctrineRepository($repository, $repositoryName,$repositoryMethod,$repositoryMethodReturnVal) { | ||
$mockEM=$this->getMock('\Doctrine\ORM\EntityManager', | ||
array('getRepository', 'getClassMetadata', 'persist', 'flush'), array(), '', false); | ||
$mockSVRepo=$this->getMock($repository,array($repositoryMethod),array(),'',false); | ||
|
||
$mockEM->expects($this->any()) | ||
->method('getClassMetadata') | ||
->will($this->returnValue((object)array('name' => 'aClass'))); | ||
$mockEM->expects($this->any()) | ||
->method('persist') | ||
->will($this->returnValue(null)); | ||
$mockEM->expects($this->any()) | ||
->method('flush') | ||
->will($this->returnValue(null)); | ||
|
||
$mockSVRepo | ||
->expects($this->any()) | ||
->method($repositoryMethod) | ||
->will($this->returnValue($repositoryMethodReturnVal)); | ||
|
||
$mockEM->expects($this->any()) | ||
->method('getRepository') | ||
->with($repositoryName) | ||
->will($this->returnValue($mockSVRepo)); | ||
|
||
return $mockEM; | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<phpunit bootstrap="./vendor/autoload.php"> | ||
|
||
<testsuites> | ||
<testsuite name="SmartCodeTestSuite"> | ||
<directory>./Tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
</phpunit> |