Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPUnit v11 support #262

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
},
"require-dev": {
"orchestra/testbench": "^7.0|^8.0|^9.0",
"phpunit/phpunit": "^9.3|^10.4"
"phpunit/phpunit": "^9.3|^10.4|^11.0"
},
"autoload": {
"psr-4": {
15 changes: 1 addition & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="true"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
verbose="true"
>
<phpunit colors="true">
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>

<php>
<env name="DB_CONNECTION" value="testing"/>
</php>
13 changes: 6 additions & 7 deletions tests/AuthBackend/AuthenticatesUsersTest.php
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
use Illuminate\Validation\ValidationException;
use Orchestra\Testbench\Factories\UserFactory;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\Test;

class AuthenticatesUsersTest extends TestCase
{
@@ -34,7 +35,7 @@ protected function defineDatabaseMigrations()
$this->loadLaravelMigrations();
}

/** @test */
#[Test]
public function it_can_authenticate_a_user()
{
Event::fake();
@@ -57,7 +58,7 @@ public function it_can_authenticate_a_user()
});
}

/** @test */
#[Test]
public function it_can_authenticate_a_user_with_remember_as_false()
{
Event::fake();
@@ -81,9 +82,7 @@ public function it_can_authenticate_a_user_with_remember_as_false()
});
}



/** @test */
#[Test]
public function it_can_authenticate_a_user_with_remember_as_true()
{
Event::fake();
@@ -107,7 +106,7 @@ public function it_can_authenticate_a_user_with_remember_as_true()
});
}

/** @test */
#[Test]
public function it_cant_authenticate_a_user_with_invalid_password()
{
$user = UserFactory::new()->create();
@@ -131,7 +130,7 @@ public function it_cant_authenticate_a_user_with_invalid_password()
], $response->exception->errors());
}

/** @test */
#[Test]
public function it_cant_authenticate_unknown_credential()
{
$request = Request::create('/login', 'POST', [
3 changes: 2 additions & 1 deletion tests/AuthBackend/RegistersUsersTest.php
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
use Illuminate\Validation\ValidationException;
use Orchestra\Testbench\Factories\UserFactory;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\Test;

class RegistersUsersTest extends TestCase
{
@@ -28,7 +29,7 @@ protected function defineDatabaseMigrations()
$this->loadLaravelMigrations();
}

/** @test */
#[Test]
public function it_can_register_a_user()
{
$request = Request::create('/register', 'POST', [
25 changes: 17 additions & 8 deletions tests/AuthBackend/ThrottleLoginsTest.php
Original file line number Diff line number Diff line change
@@ -2,20 +2,19 @@

namespace Laravel\Ui\Tests\AuthBackend;

use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\ThrottlesLogins as ThrottlesLoginsTrait;
use Orchestra\Testbench\TestCase;
use Illuminate\Http\Request;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;

class ThrottleLoginsTest extends TestCase
{
/**
* @test
* @dataProvider emailProvider
*/
#[Test]
#[DataProvider('emailProvider')]
public function it_can_generate_throttle_key(string $email, string $expectedEmail): void
{
$throttle = $this->getMockForTrait(ThrottlesLogins::class, [], '', true, true, true, ['username']);
$throttle = $this->createMock(ThrottlesLogins::class);
$throttle->method('username')->willReturn('email');
$reflection = new \ReflectionClass($throttle);
$method = $reflection->getMethod('throttleKey');
@@ -33,8 +32,18 @@ public static function emailProvider(): array
return [
'lowercase special characters' => ['ⓣⓔⓢⓣ@ⓛⓐⓡⓐⓥⓔⓛ.ⓒⓞⓜ', 'test@laravel.com'],
'uppercase special characters' => ['ⓉⒺⓈⓉ@ⓁⒶⓇⒶⓋⒺⓁ.ⒸⓄⓂ', 'test@laravel.com'],
'special character numbers' =>['test⑩⓸③@laravel.com', 'test1043@laravel.com'],
'special character numbers' => ['test⑩⓸③@laravel.com', 'test1043@laravel.com'],
'default email' => ['test@laravel.com', 'test@laravel.com'],
];
}
}

class ThrottlesLogins
{
use ThrottlesLoginsTrait;

public function username()
{
return 'email';
}
}