Skip to content

Commit

Permalink
Migrate to PHPUnit ^9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
craig410 committed Oct 29, 2020
1 parent b8b8878 commit 3fb5532
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 88 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ jobs:
- '7.4'
dependencies:
- 'default'
include:
- php_version: '7.4'
dependencies: 'lowest'

steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ that can be assembled as required.

**Warden is under heavy development and not recommended for production use outwith inGenerator.**

[![Build Status](https://travis-ci.org/ingenerator/warden-core.svg?branch=0.3.x)](https://travis-ci.org/ingenerator/warden-core)


# Installing warden-core

This isn't in packagist yet : you'll need to add our package repository to your composer.json:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"php": "~7.4.11"
},
"require-dev": {
"phpunit/phpunit": "^7.0"
"phpunit/phpunit": "^9.0"
},
"suggest": {
"ingenerator/warden-validator-symfony": "Default entity / request validation implemenation using symfony validation"
Expand Down
34 changes: 17 additions & 17 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" ?>
<?xml version="1.0"?>
<!-- Config file for PHPUnit automated tests -->
<phpunit
bootstrap="test/bootstrap.php"
cacheTokens="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite name="Unit Tests">
<directory>test/unit</directory>
</testsuite>
<testsuite name="Integration Tests">
<directory>test/integration</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="test/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage/>
<testsuites>
<testsuite name="Unit Tests">
<directory>test/unit</directory>
</testsuite>
<testsuite name="Integration Tests">
<directory>test/integration</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion test/integration/Repository/ArrayUserRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ArrayUserRepositoryTest extends UserRepositoryTest
*/
protected $storage;

public function setUp()
public function setUp(): void
{
parent::setUp();
$this->storage = new \ArrayObject;
Expand Down
22 changes: 11 additions & 11 deletions test/integration/Repository/UserRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
use Ingenerator\Warden\Core\Config\Configuration;
use Ingenerator\Warden\Core\Entity\SimpleUser;
use Ingenerator\Warden\Core\Entity\User;
use Ingenerator\Warden\Core\Repository\DuplicateUserException;
use Ingenerator\Warden\Core\Repository\UnknownUserException;
use Ingenerator\Warden\Core\Repository\UserRepository;
use PHPUnit\Framework\TestCase;

abstract class UserRepositoryTest extends \PHPUnit\Framework\TestCase
abstract class UserRepositoryTest extends TestCase
{
/**
* @var Configuration
Expand Down Expand Up @@ -55,26 +58,22 @@ public function test_saving_existing_user_does_not_change_id()
$this->assertSame($original_id, $user->getId(), 'Existing ID should be retained on save');
}

/**
* @expectedException \Ingenerator\Warden\Core\Repository\DuplicateUserException
*/
public function test_throws_duplicate_user_if_attempting_to_create_user_with_already_registered_email()
{
$email = \uniqid('duplicate').'@bar.ban';
$this->newSubject()->save($this->newUser(['email' => $email]));
$this->expectException(DuplicateUserException::class);
$this->newSubject()->save($this->newUser(['email' => $email]));
}

/**
* @expectedException \Ingenerator\Warden\Core\Repository\DuplicateUserException
*/
public function test_throws_duplicate_user_if_attempting_to_update_user_to_other_users_email()
{
$other_user = $this->newUser();
$this_user = $this->newUser();
$this->given_saved_users($other_user, $this_user);

$this_user->setEmail($other_user->getEmail());
$this->expectException(DuplicateUserException::class);
$this->newSubject()->save($this_user);
}

Expand All @@ -85,13 +84,14 @@ public function test_can_update_existing_user_with_same_email()
$this->given_saved_users($user);
$user->setPasswordHash('stuff');
$this->newSubject()->save($user);

// if we got this far successfully assert something to satisfy PHPUnit
$this->assertTrue(TRUE);
}

/**
* @expectedException \Ingenerator\Warden\Core\Repository\UnknownUserException
*/
public function test_it_throws_if_loading_user_with_unknown_id()
{
$this->expectException(UnknownUserException::class);
$this->newSubject()->load(1234);
}

Expand Down Expand Up @@ -141,7 +141,7 @@ protected function newUser(array $values = [])
return $user;
}

public function setUp()
public function setUp(): void
{
parent::setUp();
$this->config = new Configuration([]);
Expand Down
20 changes: 10 additions & 10 deletions test/unit/Config/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Ingenerator\Warden\Core\Config\Configuration;
use Ingenerator\Warden\Core\Entity\SimpleUser;
use InvalidArgumentException;

class ConfigurationTest extends \PHPUnit\Framework\TestCase
{
Expand All @@ -23,26 +24,25 @@ public function test_it_provides_default_config_when_no_overrides_provided()
$this->assertSame(SimpleUser::class, $subject->getClassName('entity', 'user'));
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage No classmap entry for foo.bar
*/
public function test_it_throws_on_attempt_to_map_undefined_class()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('No classmap entry for foo.bar');
$this->newSubject()->getClassName('foo', 'bar');
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Class \Some\Unknown\Class mapped for entity.user is not defined
*/
public function test_it_throws_if_class_mapped_to_nonexistent_class()
{
$this->newSubject(
$subject = $this->newSubject(
[
'classmap' => ['entity' => ['user' => '\Some\Unknown\Class']],
]
)->getClassName('entity', 'user');
);

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Class \Some\Unknown\Class mapped for entity.user is not defined');

$subject->getClassName('entity', 'user');
}

public function test_it_returns_mapped_class_name_if_defined()
Expand Down
3 changes: 2 additions & 1 deletion test/unit/Interactor/AbstractInteractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@


use Ingenerator\Warden\Core\Interactor\AbstractResponse;
use PHPUnit\Framework\TestCase;

abstract class AbstractInteractorTest extends \PHPUnit\Framework\TestCase
abstract class AbstractInteractorTest extends TestCase
{

protected function assertFailsWithCode($code, AbstractResponse $result)
Expand Down
7 changes: 3 additions & 4 deletions test/unit/Interactor/ActivateAccountInteractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Ingenerator\Warden\Core\Interactor\ActivateAccountResponse;
use Ingenerator\Warden\Core\Interactor\EmailVerificationRequest;
use Ingenerator\Warden\Core\Repository\ArrayUserRepository;
use Ingenerator\Warden\Core\Repository\UnknownUserException;
use Ingenerator\Warden\Core\Repository\UserRepository;
use Ingenerator\Warden\Core\Support\EmailConfirmationTokenService;
use Ingenerator\Warden\Core\UserSession\SimplePropertyUserSession;
Expand Down Expand Up @@ -60,11 +61,9 @@ public function test_it_fails_if_details_are_not_valid()

}

/**
* @expectedException \Ingenerator\Warden\Core\Repository\UnknownUserException
*/
public function test_it_throws_if_user_does_not_exist()
{
$this->expectException(UnknownUserException::class);
$this->executeWith(['user_id' => 999]);
}

Expand Down Expand Up @@ -140,7 +139,7 @@ public function test_it_logs_in_user_on_success()
$this->assertSame($user, $this->user_session->getUser());
}

public function setUp()
public function setUp(): void
{
parent::setUp();
$this->validator = ValidatorStub::alwaysValid();
Expand Down
7 changes: 3 additions & 4 deletions test/unit/Interactor/ChangeEmailInteractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Ingenerator\Warden\Core\Interactor\ChangeEmailResponse;
use Ingenerator\Warden\Core\Interactor\EmailVerificationRequest;
use Ingenerator\Warden\Core\Repository\ArrayUserRepository;
use Ingenerator\Warden\Core\Repository\UnknownUserException;
use Ingenerator\Warden\Core\Repository\UserRepository;
use Ingenerator\Warden\Core\Support\EmailConfirmationTokenService;
use Ingenerator\Warden\Core\UserSession\SimplePropertyUserSession;
Expand Down Expand Up @@ -60,11 +61,9 @@ public function test_it_fails_if_details_are_not_valid()

}

/**
* @expectedException \Ingenerator\Warden\Core\Repository\UnknownUserException
*/
public function test_it_throws_if_user_does_not_exist()
{
$this->expectException(UnknownUserException::class);
$result = $this->executeWith(['user_id' => 999]);
$this->assertFailsWithCode(ChangeEmailResponse::ERROR_UNKNOWN_USER, $result);
$this->assertSame('unknown@foo.bar', $result->getNewEmail());
Expand Down Expand Up @@ -207,7 +206,7 @@ public function test_it_logs_in_user_on_success()
$this->assertSame($user, $this->user_session->getUser());
}

public function setUp()
public function setUp(): void
{
parent::setUp();
$this->validator = ValidatorStub::alwaysValid();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Interactor/ChangePasswordInteractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function test_it_stores_and_saves_user_password_hash_on_success()
$this->user_repo->assertOneSaved($user);
}

public function setUp()
public function setUp(): void
{
parent::setUp();
$this->validator = ValidatorStub::alwaysValid();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Interactor/EmailVerificationInteractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function test_it_returns_rate_limited_response_without_sending_if_rate_li
$this->user_notification->assertNothingSent();
}

public function setUp()
public function setUp(): void
{
parent::setUp();
$this->email_token_service = new InsecureJSONTokenServiceStub;
Expand Down
22 changes: 10 additions & 12 deletions test/unit/Interactor/LoginInteractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
use Ingenerator\Warden\Core\UserSession\SimplePropertyUserSession;
use Ingenerator\Warden\Core\UserSession\UserSession;
use Ingenerator\Warden\Core\Validator\Validator;
use LogicException;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\MockObject\MockObject;
use test\mock\Ingenerator\Warden\Core\Entity\UserStub;
use test\mock\Ingenerator\Warden\Core\RateLimit\LeakyBucketStub;
use test\mock\Ingenerator\Warden\Core\Repository\SaveSpyingUserRepository;
Expand Down Expand Up @@ -64,18 +67,13 @@ class LoginInteractorTest extends AbstractInteractorTest

public function test_it_is_initialisable()
{
$this->assertInstanceOf(
'\Ingenerator\Warden\Core\Interactor\LoginInteractor',
$this->newSubject()
);
$this->assertInstanceOf(LoginInteractor::class, $this->newSubject());
}

/**
* @expectedException \LogicException
*/
public function test_it_throws_if_user_already_logged_in()
{
$this->user_session->login(new SimpleUser);
$this->expectException(LogicException::class);
$this->newSubject()->execute(LoginRequest::fromArray([]));
}

Expand Down Expand Up @@ -275,7 +273,7 @@ public function test_it_does_not_change_password_hash_on_failed_login(User $user
$this->user_repo->assertNothingSaved();
}

public function test_it_does_not_send_any_user_notification_on_succesful_login()
public function test_it_does_not_send_any_user_notification_on_successful_login()
{
$this->email_verification = $this->getMockExpectingNoCalls(
EmailVerificationInteractor::class
Expand Down Expand Up @@ -388,7 +386,7 @@ public function test_it_responds_if_email_verification_details_invalid_for_activ
}


public function setUp()
public function setUp(): void
{
parent::setUp();
$this->email_verification = new EmailVerificationInteractorSpy;
Expand Down Expand Up @@ -437,7 +435,7 @@ protected function newSubject()
/**
* @param string $className
*
* @return \PHPUnit\Framework\MockObject_MockObject
* @return MockObject
*/
protected function getMockExpectingNoCalls($className)
{
Expand Down Expand Up @@ -479,7 +477,7 @@ public function execute(EmailVerificationRequest $request)

public function assertExecutedOnceWith(EmailVerificationRequest $request)
{
\PHPUnit\Framework\Assert::assertCount(1, $this->calls);
\PHPUnit\Framework\Assert::assertEquals($request, $this->calls[0]);
Assert::assertCount(1, $this->calls);
Assert::assertEquals($request, $this->calls[0]);
}
}
2 changes: 1 addition & 1 deletion test/unit/Interactor/PasswordResetInteractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function test_it_logs_in_user_on_success()
$this->assertSame($user, $this->user_session->getUser());
}

public function setUp()
public function setUp(): void
{
parent::setUp();
$this->validator = ValidatorStub::alwaysValid();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Interactor/UserRegistrationInteractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public function test_it_does_not_log_in_user_when_inactive_on_registration()
$this->assertFalse($this->user_session->isAuthenticated());
}

public function setUp()
public function setUp(): void
{
parent::setUp();
$this->validator = ValidatorStub::alwaysValid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@ public function test_it_has_no_user_if_unset()
$this->assertSame(FALSE, $this->newSubject()->hasRecipientUser());
}

/**
* @expectedException \LogicException
*/
public function test_it_throws_if_attempt_to_get_unset_user()
{
$this->recipient_user = NULL;
$this->expectException(\LogicException::class);
$this->newSubject()->getRecipientUser();
}

Expand Down
Loading

0 comments on commit 3fb5532

Please sign in to comment.