Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test case for the trait for entity test case (the EntityTestCaseTrait)
- Loading branch information
Showing
2 changed files
with
96 additions
and
5 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,91 @@ | ||
<?php | ||
|
||
/** | ||
* (c) Meritoo.pl, http://www.meritoo.pl | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Meritoo\Test\CommonBundle\Traits\Test\Entity; | ||
|
||
use Doctrine\Common\Persistence\ObjectRepository; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Meritoo\CommonBundle\Traits\Test\Entity\EntityTestCaseTrait; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @internal | ||
* @covers \Meritoo\CommonBundle\Traits\Test\Entity\EntityTestCaseTrait | ||
*/ | ||
class EntityTestCaseTraitTest extends TestCase | ||
{ | ||
public function testPersistAndFlush(): void | ||
{ | ||
$trait = $this->getMockedTrait('persistAndFlush'); | ||
|
||
$trait | ||
->method('persistAndFlush') | ||
->willReturn(null) | ||
; | ||
|
||
static::assertNull($trait->persistAndFlush(new \stdClass())); | ||
} | ||
|
||
public function testUpdateDatabaseSchema(): void | ||
{ | ||
$trait = $this->getMockedTrait('updateDatabaseSchema'); | ||
|
||
$trait | ||
->method('updateDatabaseSchema') | ||
->willReturn(null) | ||
; | ||
|
||
static::assertNull($trait->updateDatabaseSchema()); | ||
} | ||
|
||
public function testDropDatabaseSchema(): void | ||
{ | ||
$trait = $this->getMockedTrait('dropDatabaseSchema'); | ||
|
||
$trait | ||
->method('dropDatabaseSchema') | ||
->willReturn(null) | ||
; | ||
|
||
static::assertNull($trait->dropDatabaseSchema()); | ||
} | ||
|
||
public function testGetEntityManager(): void | ||
{ | ||
$trait = $this->getMockedTrait('getEntityManager'); | ||
$entityManager = $this->createMock(EntityManagerInterface::class); | ||
|
||
$trait | ||
->method('getEntityManager') | ||
->willReturn($entityManager) | ||
; | ||
|
||
static::assertInstanceOf(EntityManagerInterface::class, $trait->getEntityManager()); | ||
} | ||
|
||
public function testGetRepository(): void | ||
{ | ||
$trait = $this->getMockedTrait('getRepository'); | ||
$repository = $this->createMock(ObjectRepository::class); | ||
|
||
$trait | ||
->method('getRepository') | ||
->willReturn($repository) | ||
; | ||
|
||
static::assertInstanceOf(ObjectRepository::class, $trait->getRepository(\stdClass::class)); | ||
} | ||
|
||
private function getMockedTrait(string $method): MockObject | ||
{ | ||
return $this->getMockForTrait(EntityTestCaseTrait::class, [], '', true, true, true, [$method]); | ||
} | ||
} |