Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit a5f631e

Browse files
thexpandweierophinney
authored andcommitted
Add tests for more complete code coverage for the ClientRepository
1 parent 4ca5120 commit a5f631e

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

test/Repository/Pdo/ClientRepositoryTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,44 @@ public function testGetClientEntityReturnsNullIfNoRowReturned()
6060
);
6161
}
6262

63+
public function testGetClientEntityReturnsCorrectEntity()
64+
{
65+
$name = 'foo';
66+
$redirect = 'bar';
67+
68+
$statement = $this->prophesize(PDOStatement::class);
69+
$statement->bindParam(':clientIdentifier', 'client_id')->shouldBeCalled();
70+
$statement->execute()->will(function () use ($statement, $name, $redirect) {
71+
$statement->fetch()->willReturn([
72+
'name' => $name,
73+
'redirect' => $redirect,
74+
]);
75+
return null;
76+
});
77+
78+
$this->pdo
79+
->prepare(Argument::containingString('SELECT * FROM oauth_clients'))
80+
->will([$statement, 'reveal']);
81+
82+
$this->prophesize(ClientEntityInterface::class);
83+
84+
/** @var ClientEntityInterface $client */
85+
$client = $this->repo->getClientEntity('client_id');
86+
87+
$this->assertInstanceOf(
88+
ClientEntityInterface::class,
89+
$client
90+
);
91+
$this->assertEquals(
92+
$name,
93+
$client->getName()
94+
);
95+
$this->assertEquals(
96+
[$redirect],
97+
$client->getRedirectUri()
98+
);
99+
}
100+
63101
public function invalidGrants()
64102
{
65103
return [
@@ -76,6 +114,30 @@ public function invalidGrants()
76114
];
77115
}
78116

117+
public function testValidateClientReturnsFalseIfNoRowReturned()
118+
{
119+
$statement = $this->prophesize(PDOStatement::class);
120+
$statement->bindParam(':clientIdentifier', 'client_id')->shouldBeCalled();
121+
$statement->execute()->will(function () use ($statement) {
122+
$statement->fetch()->willReturn([]);
123+
return null;
124+
});
125+
126+
$this->pdo
127+
->prepare(Argument::containingString('SELECT * FROM oauth_clients'))
128+
->will([$statement, 'reveal']);
129+
130+
$client = $this->prophesize(ClientEntityInterface::class);
131+
132+
$this->assertFalse(
133+
$this->repo->validateClient(
134+
'client_id',
135+
'',
136+
'password'
137+
)
138+
);
139+
}
140+
79141
/**
80142
* @dataProvider invalidGrants
81143
*/

0 commit comments

Comments
 (0)