Skip to content

Commit 8c0383e

Browse files
committed
Repair unit tests
Setting correct expectancies on mock translator
1 parent 9b2e0d4 commit 8c0383e

File tree

5 files changed

+69
-74
lines changed

5 files changed

+69
-74
lines changed

tests/unit/OpenConext/EngineBlock/Metadata/Factory/AbstractEntityTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use OpenConext\EngineBlock\Metadata\Service;
3434
use OpenConext\EngineBlock\Metadata\ShibMdScope;
3535
use OpenConext\EngineBlock\Metadata\X509\X509Certificate;
36+
use PHPUnit\Framework\MockObject\MockObject;
3637
use PHPUnit\Framework\TestCase;
3738
use ReflectionClass;
3839
use ReflectionProperty;
@@ -512,6 +513,64 @@ protected function getServiceProviderMockProperties()
512513
];
513514
}
514515

516+
protected function setTranslationExpectancies(MockObject $translator)
517+
{
518+
$translator->expects($this->at(0))
519+
->method('trans')
520+
->with('suite_name')
521+
->willReturn('test-suite');
522+
523+
$translator->expects($this->at(1))
524+
->method('trans')
525+
->with('metadata_organization_name')
526+
->willReturn('configuredOrganizationName');
527+
528+
$translator->expects($this->at(2))
529+
->method('trans')
530+
->with('metadata_organization_name', [], null, 'nl')
531+
->willReturn('configuredOrganizationName');
532+
533+
$translator->expects($this->at(3))
534+
->method('trans')
535+
->with('metadata_organization_displayname', [], null, 'nl')
536+
->willReturn('configuredOrganizationDisplayName');
537+
538+
$translator->expects($this->at(4))
539+
->method('trans')
540+
->with('metadata_organization_url', [], null, 'nl')
541+
->willReturn('configuredOrganizationUrl');
542+
543+
$translator->expects($this->at(5))
544+
->method('trans')
545+
->with('metadata_organization_name', [], null, 'en')
546+
->willReturn('configuredOrganizationName');
547+
548+
$translator->expects($this->at(6))
549+
->method('trans')
550+
->with('metadata_organization_displayname', [], null, 'en')
551+
->willReturn('configuredOrganizationDisplayName');
552+
553+
$translator->expects($this->at(7))
554+
->method('trans')
555+
->with('metadata_organization_url', [], null, 'en')
556+
->willReturn('configuredOrganizationUrl');
557+
558+
$translator->expects($this->at(8))
559+
->method('trans')
560+
->with('metadata_organization_name', [], null, 'pt')
561+
->willReturn('configuredOrganizationName');
562+
563+
$translator->expects($this->at(9))
564+
->method('trans')
565+
->with('metadata_organization_displayname', [], null, 'pt')
566+
->willReturn('configuredOrganizationDisplayName');
567+
568+
$translator->expects($this->at(10))
569+
->method('trans')
570+
->with('metadata_organization_url', [], null, 'pt')
571+
->willReturn('configuredOrganizationUrl');
572+
}
573+
515574
private function getParameters($className, $skipParameters = [])
516575
{
517576
$results = [];

tests/unit/OpenConext/EngineBlock/Metadata/Factory/Decorator/EngineblockIdentityProviderInformationTest.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,8 @@ public function test_methods()
3131
$adapter = $this->createIdentityProviderAdapter();
3232

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

39-
$translator->expects($this->at(1))
40-
->method('trans')
41-
->with('metadata_organization_name')
42-
->willReturn('configuredOrganizationName');
43-
44-
$translator->expects($this->at(2))
45-
->method('trans')
46-
->with('metadata_organization_name')
47-
->willReturn('configuredOrganizationName');
48-
49-
$translator->expects($this->at(3))
50-
->method('trans')
51-
->with('metadata_organization_displayname')
52-
->willReturn('configuredOrganizationDisplayName');
53-
54-
$translator->expects($this->at(4))
55-
->method('trans')
56-
->with('metadata_organization_url')
57-
->willReturn('configuredOrganizationUrl');
35+
$this->setTranslationExpectancies($translator);
5836

5937
$configuration = new EngineBlockConfiguration(
6038
$translator,

tests/unit/OpenConext/EngineBlock/Metadata/Factory/Decorator/EngineblockServiceProviderInformationTest.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,8 @@ public function test_methods()
3232
$adapter = $this->createServiceProviderAdapter();
3333

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

40-
$translator->expects($this->at(1))
41-
->method('trans')
42-
->with('metadata_organization_name')
43-
->willReturn('configuredOrganizationName');
44-
45-
$translator->expects($this->at(2))
46-
->method('trans')
47-
->with('metadata_organization_name')
48-
->willReturn('configuredOrganizationName');
49-
50-
$translator->expects($this->at(3))
51-
->method('trans')
52-
->with('metadata_organization_displayname')
53-
->willReturn('configuredOrganizationDisplayName');
54-
55-
$translator->expects($this->at(4))
56-
->method('trans')
57-
->with('metadata_organization_url')
58-
->willReturn('configuredOrganizationUrl');
36+
$this->setTranslationExpectancies($translator);
5937

6038
$configuration = new EngineBlockConfiguration(
6139
$translator,

tests/unit/OpenConext/EngineBlock/Metadata/Factory/Factory/ServiceProviderFactoryTest.php

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
namespace OpenConext\EngineBlock\Metadata\Factory\Factory;
1919

2020
use EngineBlock_Attributes_Metadata as AttributesMetadata;
21-
use Mockery\Mock;
2221
use OpenConext\EngineBlock\Exception\MissingParameterException;
2322
use OpenConext\EngineBlock\Metadata\Coins;
2423
use OpenConext\EngineBlock\Metadata\ContactPerson;
25-
use OpenConext\EngineBlock\Metadata\Entity\ServiceProvider;
2624
use OpenConext\EngineBlock\Metadata\Factory\AbstractEntityTest;
2725
use OpenConext\EngineBlock\Metadata\Factory\ServiceProviderEntityInterface;
2826
use OpenConext\EngineBlock\Metadata\Factory\ValueObject\EngineBlockConfiguration;
@@ -114,30 +112,7 @@ public function test_create_stepup_entity_from()
114112

115113
public function test_eb_properties()
116114
{
117-
$this->translator->expects($this->at(0))
118-
->method('trans')
119-
->with('suite_name')
120-
->willReturn('test-suite');
121-
122-
$this->translator->expects($this->at(1))
123-
->method('trans')
124-
->with('metadata_organization_name')
125-
->willReturn('configuredOrganizationName');
126-
127-
$this->translator->expects($this->at(2))
128-
->method('trans')
129-
->with('metadata_organization_name')
130-
->willReturn('configuredOrganizationName');
131-
132-
$this->translator->expects($this->at(3))
133-
->method('trans')
134-
->with('metadata_organization_displayname')
135-
->willReturn('configuredOrganizationDisplayName');
136-
137-
$this->translator->expects($this->at(4))
138-
->method('trans')
139-
->with('metadata_organization_url')
140-
->willReturn('configuredOrganizationUrl');
115+
$this->setTranslationExpectancies($this->translator);
141116

142117
$this->configuration = new EngineBlockConfiguration(
143118
$this->translator,

tests/unit/OpenConext/EngineBlock/Metadata/Factory/ValueObject/EngineBlockConfigurationTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,22 @@ public function test_configuration_creation()
4242
->shouldReceive('trans')
4343
->with('suite_name')->once()
4444
->andReturn($suitName);
45+
$translator
46+
->shouldReceive('trans')
47+
->with('metadata_organization_name', [], null, 'en')->once()
48+
->andReturn($orgName);
4549
$translator
4650
->shouldReceive('trans')
4751
->with('metadata_organization_name')->once()
4852
->andReturn($orgName);
4953
$translator
5054
->shouldReceive('trans')
51-
->with('metadata_organization_displayname')->once()
55+
->with('metadata_organization_displayname', [], null, 'en')->once()
5256
->andReturn($orgDisplayName);
57+
5358
$translator
5459
->shouldReceive('trans')
55-
->with('metadata_organization_url')->once()
60+
->with('metadata_organization_url', [], null, 'en')->once()
5661
->andReturn($orgUrl);
5762

5863
$mail = 'mail@example.org';

0 commit comments

Comments
 (0)