Skip to content

Commit

Permalink
Merge pull request #19 from ingenerator/switch-to-github-actions
Browse files Browse the repository at this point in the history
Switch to Github Actions instead of Travis
  • Loading branch information
craig410 authored Oct 29, 2020
2 parents d0bb481 + ace6ade commit d2f6c6a
Show file tree
Hide file tree
Showing 21 changed files with 134 additions and 109 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Run tests
on:
push:
branches:
# Only mainline branches, features etc are covered on the pull_request trigger
- '*.x'
pull_request:

jobs:
run-tests:
runs-on: ubuntu-latest
name: Run tests
strategy:
fail-fast: false
matrix:
php_version:
- '7.4'
dependencies:
- 'default'

steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
tools: composer:v2

- name: Checkout
uses: actions/checkout@v2

- name: Get composer cache directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-${{ matrix.dependencies }}
- name: Install composer dependencies
env:
DEPENDENCIES: ${{ matrix.dependencies }}
run: |
if [ $DEPENDENCIES == 'lowest' ]
then
composer update --prefer-lowest --no-interaction --no-suggest --no-progress
else
composer install --no-interaction --no-suggest --no-progress
fi
- name: Run unit tests
run: |
vendor/bin/phpunit
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### Unreleased

### v1.1.0 (2020-10-29)

* Support php7.4

### v1.0.0 (2019-04-03)

* Ensure php7.2 support
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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
}
],
"require": {
"php": "^7.2"
"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
Loading

0 comments on commit d2f6c6a

Please sign in to comment.