Skip to content

Commit

Permalink
refactor: Get rid of mock, use real objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Oct 5, 2020
1 parent e3d4136 commit 1fe2c09
Showing 1 changed file with 129 additions and 150 deletions.
279 changes: 129 additions & 150 deletions spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ public function it_can_get_specific_attribute()

$this
->getAuthenticationFactors()
->shouldReturn(['ecphp@ec.europa.eu']);
->shouldReturn([
'moniker' => [
'@value' => 'ecphp@ec.europa.eu',
'@attributes' => [
'number' => '1',
],
],
]);

$this
->getDepartmentNumber()
Expand Down Expand Up @@ -116,7 +123,7 @@ public function it_can_get_specific_attribute()

$this
->getStrengths()
->shouldReturn(['bar']);
->shouldReturn(['strength1']);

$this
->getTelephoneNumber()
Expand All @@ -137,6 +144,18 @@ public function it_can_get_specific_attribute()
$this
->getAttributes()
->shouldReturn($this->getAttributesData());

$this
->getUserManager()
->shouldReturn('userManager');

$this
->getTimeZone()
->shouldReturn('timeZone');

$this
->getProxyGrantingProtocol()
->shouldReturn('proxyGrantingProtocol');
}

public function it_can_get_the_attributes_only(CasUserInterface $user)
Expand All @@ -162,10 +181,6 @@ public function it_is_initializable()
->getSalt()
->shouldBeNull();

$this
->getAttribute('user')
->shouldReturn('username');

$this
->getUser()
->shouldReturn('username');
Expand All @@ -179,7 +194,7 @@ public function it_is_initializable()
->shouldBeNull();
}

public function let(CasUserInterface $user)
public function let()
{
$body = <<<'EOF'
<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">
Expand All @@ -193,12 +208,72 @@ public function let(CasUserInterface $user)
proxyGrantingTicket
</cas:proxyGrantingTicket>
<cas:attributes>
<cas:departmentNumber>
departmentNumber
</cas:departmentNumber>
<cas:domain>
domain
</cas:domain>
<cas:domainUsername>
domainUsername
</cas:domainUsername>
<cas:email>
email
</cas:email>
<cas:employeeNumber>
employeeNumber
</cas:employeeNumber>
<cas:employeeType>
employeeType
</cas:employeeType>
<cas:firstName>
firstName
</cas:firstName>
<cas:lastName>
lastName
</cas:lastName>
<cas:locale>
locale
</cas:locale>
<cas:loginDate>
loginDate
</cas:loginDate>
<cas:orgId>
orgId
</cas:orgId>
<cas:sso>
sso
</cas:sso>
<cas:strengths number="1">
<cas:strength>strength1</cas:strength>
</cas:strengths>
<cas:telephoneNumber>
telephoneNumber
</cas:telephoneNumber>
<cas:teleworkingPriority>
teleworkingPriority
</cas:teleworkingPriority>
<cas:ticketType>
ticketType
</cas:ticketType>
<cas:uid>
uid
</cas:uid>
<cas:authenticationFactors>
<cas:moniker number="1">
ecphp@ec.europa.eu
</cas:moniker>
</cas:authenticationFactors>
<cas:assuranceLevel>40</cas:assuranceLevel>
<cas:proxyGrantingProtocol>
proxyGrantingProtocol
</cas:proxyGrantingProtocol>
<cas:userManager>
userManager
</cas:userManager>
<cas:timeZone>
timeZone
</cas:timeZone>
<cas:groups number="2">
<cas:group>group1</cas:group>
<cas:group>group2</cas:group>
Expand All @@ -217,134 +292,7 @@ public function let(CasUserInterface $user)
$response = new Response(200, ['Content-Type' => 'application/xml'], $body);
$data = (new Introspector())->parse($response)['serviceResponse']['authenticationSuccess'];

$user
->beConstructedWith($data);

$user
->getAttribute('extendedAttributes', [])
->willReturn([
'extendedAttribute' => [
'attributeValue' => [
'value1',
'value2',
],
'@attributes' => [
'name' => 'attr1',
],
],
]);

$user
->get('foo', 'bar')
->willReturn('bar');

$user
->getUsername()
->willReturn('username');

$user
->getAttribute('user', null)
->willReturn('username');

$user
->getPgt()
->willReturn('proxyGrantingTicket');

$user
->getAttribute('assuranceLevel')
->willReturn($data['attributes']['assuranceLevel']);

$user
->getAttribute('authenticationFactors', [])
->willReturn([
'ecphp@ec.europa.eu',
]);

$user
->getAttribute('departmentNumber')
->willReturn('departmentNumber');

$user
->getAttribute('domain')
->willReturn('domain');

$user
->getAttribute('domainUsername')
->willReturn('domainUsername');

$user
->getAttribute('email')
->willReturn('email');

$user
->getAttribute('employeeNumber')
->willReturn('employeeNumber');

$user
->getAttribute('employeeType')
->willReturn('employeeType');

$user
->getAttribute('firstName')
->willReturn('firstName');

$user
->getAttribute('groups', ['group' => []])
->willReturn([
'group' => [
'group1',
'group2',
],
'@attributes' => [
'number' => 2,
],
]);

$user
->getAttribute('lastName')
->willReturn('lastName');

$user
->getAttribute('locale')
->willReturn('locale');

$user
->getAttribute('loginDate')
->willReturn('loginDate');

$user
->getAttribute('orgId')
->willReturn('orgId');

$user
->getAttribute('sso')
->willReturn('sso');

$user
->getAttribute('strengths', [])
->willReturn([
'bar',
]);

$user
->getAttribute('telephoneNumber')
->willReturn('telephoneNumber');

$user
->getAttribute('teleworkingPriority')
->willReturn('teleworkingPriority');

$user
->getAttribute('ticketType')
->willReturn('ticketType');

$user
->getAttribute('uid')
->willReturn('uid');

$user
->getAttributes()
->willReturn($this->getAttributesData());
$user = new CasUser($data);

$this
->beConstructedWith($user);
Expand All @@ -354,26 +302,47 @@ private function getAttributesData(): array
{
return [
'departmentNumber' => 'departmentNumber',
'domain' => 'domain',
'domainUsername' => 'domainUsername',
'email' => 'email',
'employeeNumber' => 'employeeNumber',
'employeeType' => 'employeeType',
'extendedAttributes' => [
'extendedAttribute' => [
[
'attr1' => [
'value1',
'value2',
],
'firstName' => 'firstName',
'lastName' => 'lastName',
'locale' => 'locale',
'loginDate' => 'loginDate',
'orgId' => 'orgId',
'sso' => 'sso',
'strengths' => [
'strength' => [
'strength1',
],
'@attributes' => [
'number' => '1',
],
],
'telephoneNumber' => 'telephoneNumber',
'teleworkingPriority' => 'teleworkingPriority',
'ticketType' => 'ticketType',
'uid' => 'uid',
'authenticationFactors' => [
'moniker' => [
'@value' => 'ecphp@ec.europa.eu',
'@attributes' => [
'number' => '1',
],
],
],
'assuranceLevel' => '40',
'proxyGrantingProtocol' => 'proxyGrantingProcotol',
'userManager' => 'userManager',
'timeZone' => 'timeZone',
'firstName' => 'firstName',
'lastName' => 'lastName',
'domain' => 'domain',
'domainUsername' => 'domainUsername',
'telephoneNumber' => 'telephoneNumber',
'locale' => 'locale',
'assuranceLevel' => '40',
'uid' => 'uid',
'orgId' => 'orgId',
'teleworkingPriority' => 'teleworkingPriority',
Expand All @@ -382,19 +351,29 @@ private function getAttributesData(): array
'group1',
'group2',
],
],
'strengths' => [
'strength' => [
'bar',
'@attributes' => [
'number' => '2',
],
],
'authenticationFactors' => [
'ecphp@ec.europa.eu',
'extendedAttributes' => [
'extendedAttribute' => [
[
'attributeValue' => [
'rex',
'snoopy',
],
'@attributes' => [
'name' => 'http://stork.eu/motherInLawDogName',
],
],
],
],
'loginDate' => 'loginDate',
'sso' => 'sso',
'ticketType' => 'ticketType',
'assuranceLevel' => '40',
'proxyGrantingProtocol' => 'proxyGrantingProtocol',
'timeZone' => 'timeZone',
'userManager' => 'userManager',
];
}
}

0 comments on commit 1fe2c09

Please sign in to comment.