Skip to content

Commit

Permalink
Repair unit tests
Browse files Browse the repository at this point in the history
Setting correct expectancies on mock translator
  • Loading branch information
MKodde committed Aug 27, 2024
1 parent 9b2e0d4 commit 51a7a38
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OpenConext\EngineBlock\Metadata\Service;
use OpenConext\EngineBlock\Metadata\ShibMdScope;
use OpenConext\EngineBlock\Metadata\X509\X509Certificate;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionProperty;
Expand Down Expand Up @@ -512,6 +513,64 @@ protected function getServiceProviderMockProperties()
];
}

protected function setTranslationExpectancies(MockObject $translator)
{
$translator->expects($this->at(0))
->method('trans')
->with('suite_name')
->willReturn('test-suite');

$translator->expects($this->at(1))
->method('trans')
->with('metadata_organization_name')
->willReturn('configuredOrganizationName');

$translator->expects($this->at(2))
->method('trans')
->with('metadata_organization_name', [], null, 'nl')
->willReturn('configuredOrganizationName');

$translator->expects($this->at(3))
->method('trans')
->with('metadata_organization_displayname', [], null, 'nl')
->willReturn('configuredOrganizationDisplayName');

$translator->expects($this->at(4))
->method('trans')
->with('metadata_organization_url', [], null, 'nl')
->willReturn('configuredOrganizationUrl');

$translator->expects($this->at(5))
->method('trans')
->with('metadata_organization_name', [], null, 'en')
->willReturn('configuredOrganizationName');

$translator->expects($this->at(6))
->method('trans')
->with('metadata_organization_displayname', [], null, 'en')
->willReturn('configuredOrganizationDisplayName');

$translator->expects($this->at(7))
->method('trans')
->with('metadata_organization_url', [], null, 'en')
->willReturn('configuredOrganizationUrl');

$translator->expects($this->at(8))
->method('trans')
->with('metadata_organization_name', [], null, 'pt')
->willReturn('configuredOrganizationName');

$translator->expects($this->at(9))
->method('trans')
->with('metadata_organization_displayname', [], null, 'pt')
->willReturn('configuredOrganizationDisplayName');

$translator->expects($this->at(10))
->method('trans')
->with('metadata_organization_url', [], null, 'pt')
->willReturn('configuredOrganizationUrl');
}

private function getParameters($className, $skipParameters = [])
{
$results = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use OpenConext\EngineBlock\Metadata\Factory\ValueObject\EngineBlockConfiguration;
use OpenConext\EngineBlock\Metadata\Logo;
use OpenConext\EngineBlock\Metadata\Organization;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Translation\TranslatorInterface;

class EngineblockIdentityProviderInformationTest extends AbstractEntityTest
Expand All @@ -31,30 +32,8 @@ public function test_methods()
$adapter = $this->createIdentityProviderAdapter();

$translator = $this->createMock(TranslatorInterface::class);
$translator->expects($this->at(0))
->method('trans')
->with('suite_name')
->willReturn('test-suite');

$translator->expects($this->at(1))
->method('trans')
->with('metadata_organization_name')
->willReturn('configuredOrganizationName');

$translator->expects($this->at(2))
->method('trans')
->with('metadata_organization_name')
->willReturn('configuredOrganizationName');

$translator->expects($this->at(3))
->method('trans')
->with('metadata_organization_displayname')
->willReturn('configuredOrganizationDisplayName');

$translator->expects($this->at(4))
->method('trans')
->with('metadata_organization_url')
->willReturn('configuredOrganizationUrl');
$this->setTranslationExpectancies($translator);

$configuration = new EngineBlockConfiguration(
$translator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,8 @@ public function test_methods()
$adapter = $this->createServiceProviderAdapter();

$translator = $this->createMock(TranslatorInterface::class);
$translator->expects($this->at(0))
->method('trans')
->with('suite_name')
->willReturn('test-suite');

$translator->expects($this->at(1))
->method('trans')
->with('metadata_organization_name')
->willReturn('configuredOrganizationName');

$translator->expects($this->at(2))
->method('trans')
->with('metadata_organization_name')
->willReturn('configuredOrganizationName');

$translator->expects($this->at(3))
->method('trans')
->with('metadata_organization_displayname')
->willReturn('configuredOrganizationDisplayName');

$translator->expects($this->at(4))
->method('trans')
->with('metadata_organization_url')
->willReturn('configuredOrganizationUrl');
$this->setTranslationExpectancies($translator);

$configuration = new EngineBlockConfiguration(
$translator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,30 +114,7 @@ public function test_create_stepup_entity_from()

public function test_eb_properties()
{
$this->translator->expects($this->at(0))
->method('trans')
->with('suite_name')
->willReturn('test-suite');

$this->translator->expects($this->at(1))
->method('trans')
->with('metadata_organization_name')
->willReturn('configuredOrganizationName');

$this->translator->expects($this->at(2))
->method('trans')
->with('metadata_organization_name')
->willReturn('configuredOrganizationName');

$this->translator->expects($this->at(3))
->method('trans')
->with('metadata_organization_displayname')
->willReturn('configuredOrganizationDisplayName');

$this->translator->expects($this->at(4))
->method('trans')
->with('metadata_organization_url')
->willReturn('configuredOrganizationUrl');
$this->setTranslationExpectancies($this->translator);

$this->configuration = new EngineBlockConfiguration(
$this->translator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,22 @@ public function test_configuration_creation()
->shouldReceive('trans')
->with('suite_name')->once()
->andReturn($suitName);
$translator
->shouldReceive('trans')
->with('metadata_organization_name', [], null, 'en')->once()
->andReturn($orgName);
$translator
->shouldReceive('trans')
->with('metadata_organization_name')->once()
->andReturn($orgName);
$translator
->shouldReceive('trans')
->with('metadata_organization_displayname')->once()
->with('metadata_organization_displayname', [], null, 'en')->once()
->andReturn($orgDisplayName);

$translator
->shouldReceive('trans')
->with('metadata_organization_url')->once()
->with('metadata_organization_url', [], null, 'en')->once()
->andReturn($orgUrl);

$mail = '[email protected]';
Expand Down

0 comments on commit 51a7a38

Please sign in to comment.