Skip to content

Commit

Permalink
fix: improve test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielberthier committed May 16, 2023
1 parent e16c503 commit 43146c6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 41 deletions.
39 changes: 18 additions & 21 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 12 additions & 13 deletions tests/Domain/UseCases/Auth/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ public function makeService($repository, $comparer): LoginServiceInterface
return new Login($repository, $comparer);
}

/**
* Create a mocked repository.
*
* @return MockObject
*/
public function mockRepository()

public function mockRepository(): AccountRepository|MockObject
{
return $this->getMockBuilder(AccountRepository::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -133,23 +129,26 @@ public function testShouldCallHashComparerWithCorrectValues()
// Test should throw if password provided differs from retrieved by repository
public function testShouldThrowIfPasswordDiffersFromRetrievedOne()
{
$repository = $this->mockRepository();
$repository->method('findByAccess')->willReturn(
new Account(2,
$mockRepository = $this->mockRepository();
$mockRepository->method('findByAccess')->willReturn(
new Account(
2,
password: 'hashed_password',
email: 'mail.com',
username: 'user')
username: 'user'
)
);

$this->expectException(IncorrectPasswordException::class);
/**
* @var MockObject
*/

$mock = $this->getMockBuilder(ComparerInterface::class)
->disableOriginalConstructor()
->getMock();
$mock->expects($this->once())->method('compare')->willReturn(false);

/** @var AccountRepository */
$repository = $mockRepository;

$loginService = $this->makeService($repository, $mock);

$credentialsStub = $this->makeCredentials();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testShouldInterceptHttpCookieRefresh()
;

/**
* @var Container
* @var \Psr\Container\ContainerInterface
*/
$container = $this->getContainer();

Expand All @@ -44,4 +44,4 @@ public function testShouldInterceptHttpCookieRefresh()

assertNotNull($response);
}
}
}
3 changes: 1 addition & 2 deletions tests/Presentation/Validation/MarkerValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use App\Presentation\Helpers\Validation\Validators\Interfaces\ValidationInterface;

use function PHPUnit\Framework\assertNotNull;
use function PHPUnit\Framework\assertTrue;
use Prophecy\PhpUnit\ProphecyTrait;
use Tests\TestCase;

Expand Down Expand Up @@ -98,4 +97,4 @@ public function testShouldPassAsset()

$this->assertNull($this->sut->validate($body['marker']));
}
}
}
6 changes: 3 additions & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TestCase extends PHPUnit_TestCase

public static function createDatabase()
{
/** @var ContainerInterface */
/** @var \Psr\Container\ContainerInterface */
$container = self::$container;
/** @var EntityManager */
$entityManager = $container->get(EntityManager::class);
Expand All @@ -38,11 +38,11 @@ public static function createDatabase()

final public static function truncateDatabase()
{
/** @var ContainerInterface */
/** @var \Psr\Container\ContainerInterface */
$container = self::$container;
/** @var EntityManager */
$entityManager = $container->get(EntityManager::class);
$schemaTool = new SchemaTool($entityManager);
$schemaTool->dropDatabase();
}
}
}

0 comments on commit 43146c6

Please sign in to comment.