-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(chore): refactor some stuff for better output and implement test
- Loading branch information
1 parent
83a7265
commit fe90047
Showing
5 changed files
with
130 additions
and
15 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
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,78 @@ | ||
<?php | ||
|
||
namespace Studit\H5PBundle\Tests\Service; | ||
|
||
use PHPUnit\Framework\MockObject\Exception; | ||
use PHPUnit\Framework\TestCase; | ||
use Studit\H5PBundle\Service\DoctrineParser; | ||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\ORM\Query\Parameter; | ||
use Studit\H5PBundle\Utils\VersionORM; | ||
|
||
class DoctrineParserTest extends TestCase | ||
{ | ||
/** | ||
* Test that buildParams returns an ArrayCollection for Doctrine ORM v3. | ||
* @throws Exception | ||
*/ | ||
public function testBuildParamsForDoctrineV3() | ||
{ | ||
// Mock VersionProvider to simulate Doctrine v2 version | ||
$mockVersionORM = $this->createMock(VersionORM::class); | ||
$mockVersionORM->method('getDoctrineVersion') | ||
->willReturn('3.1.0'); // Simulate Doctrine v2 version | ||
// Inject the mocked version provider into DoctrineParser | ||
$doctrineParser = new DoctrineParser($mockVersionORM); | ||
|
||
// Define test parameters | ||
$params = [ | ||
'param1' => 'value1', | ||
'param2' => 'value2', | ||
]; | ||
|
||
// Call the method under test | ||
$result = $doctrineParser->buildParams($params); | ||
|
||
// Assert that the result is an instance of ArrayCollection | ||
$this->assertInstanceOf(ArrayCollection::class, $result); | ||
|
||
// Assert that the ArrayCollection contains Parameter objects | ||
foreach ($result as $param) { | ||
$this->assertInstanceOf(Parameter::class, $param); | ||
} | ||
|
||
// Assert that the parameters inside the Parameter objects match the input parameters | ||
$this->assertEquals('value1', $result[0]->getValue()); | ||
$this->assertEquals('value2', $result[1]->getValue()); | ||
} | ||
|
||
/** | ||
* Test that buildParams returns the original parameters as an array for Doctrine ORM v2. | ||
* @throws Exception | ||
*/ | ||
public function testBuildParamsForDoctrineV2() | ||
{ | ||
// Mock VersionProvider to simulate Doctrine v2 version | ||
$mockVersionORM = $this->createMock(VersionORM::class); | ||
$mockVersionORM->method('getDoctrineVersion') | ||
->willReturn('2.9.3'); // Simulate Doctrine v2 version | ||
|
||
// Inject the mocked version provider into DoctrineParser | ||
$doctrineParser = new DoctrineParser($mockVersionORM); | ||
|
||
// Define test parameters | ||
$params = [ | ||
'param1' => 'value1', | ||
'param2' => 'value2', | ||
]; | ||
|
||
// Call the method under test | ||
$result = $doctrineParser->buildParams($params); | ||
|
||
// Assert that the result is an array (not an ArrayCollection) | ||
$this->assertIsArray($result); | ||
|
||
// Assert that the returned array contains the same values as the input parameters | ||
$this->assertSame($params, $result); | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace Studit\H5PBundle\Utils; | ||
|
||
use Composer\InstalledVersions; | ||
|
||
/** | ||
* VersionProvider class provides a simple interface to retrieve the version of the Doctrine ORM package. | ||
* It wraps the `InstalledVersions::getVersion` method, allowing easier testing and version checking. | ||
*/ | ||
class VersionORM | ||
{ | ||
/** | ||
* Retrieves the installed version of the Doctrine ORM package. | ||
* | ||
* This method calls `InstalledVersions::getVersion('doctrine/orm')` and returns the version string | ||
* for the Doctrine ORM package if available. If the package is not found, it returns null. | ||
* | ||
* @return string|null The version of Doctrine ORM if installed, null otherwise. | ||
*/ | ||
public function getDoctrineVersion(): ?string | ||
{ | ||
return InstalledVersions::getVersion('doctrine/orm'); | ||
} | ||
} |