diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 734288b..f27a1ee 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,9 +18,9 @@ jobs: matrix: php: [8.1, 8.2, 8.3] laravel: [10, 11] - exclude: - - php: 8.1 - laravel: 11 + exclude: + - php: 8.1 + laravel: 11 name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} diff --git a/composer.json b/composer.json index 114c227..b787a2e 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "illuminate/support": "^10.0|^11.0", "illuminate/testing": "^10.0|^11.0", "mockery/mockery": "^1.0", - "phpunit/phpunit": "^10.0.7", + "phpunit/phpunit": "^10.1|^11.0", "symfony/console": "^6.2|^7.0", "symfony/css-selector": "^6.2|^7.0", "symfony/dom-crawler": "^6.2|^7.0", diff --git a/src/Constraints/FormFieldConstraint.php b/src/Constraints/FormFieldConstraint.php index cf7849c..b08ef60 100644 --- a/src/Constraints/FormFieldConstraint.php +++ b/src/Constraints/FormFieldConstraint.php @@ -4,21 +4,14 @@ use Symfony\Component\DomCrawler\Crawler; -abstract class FormFieldConstraint extends PageConstraint +abstract readonly class FormFieldConstraint extends PageConstraint { - /** - * The name or ID of the element. - * - * @var string - */ - protected $selector; - /** * The expected value. * * @var string */ - protected $value; + protected string $value; /** * Create a new constraint instance. @@ -27,9 +20,8 @@ abstract class FormFieldConstraint extends PageConstraint * @param mixed $value * @return void */ - public function __construct($selector, $value) + public function __construct(protected string $selector, $value) { - $this->selector = $selector; $this->value = (string) $value; } diff --git a/src/Constraints/HasElement.php b/src/Constraints/HasElement.php index 65efb6f..d596c14 100644 --- a/src/Constraints/HasElement.php +++ b/src/Constraints/HasElement.php @@ -4,22 +4,8 @@ use Symfony\Component\DomCrawler\Crawler; -class HasElement extends PageConstraint +readonly class HasElement extends PageConstraint { - /** - * The name or ID of the element. - * - * @var string - */ - protected $selector; - - /** - * The attributes the element should have. - * - * @var array - */ - protected $attributes; - /** * Create a new constraint instance. * @@ -27,10 +13,11 @@ class HasElement extends PageConstraint * @param array $attributes * @return void */ - public function __construct($selector, array $attributes = []) - { - $this->selector = $selector; - $this->attributes = $attributes; + public function __construct( + protected string $selector, + protected array $attributes = [] + ) { + // } /** diff --git a/src/Constraints/HasInElement.php b/src/Constraints/HasInElement.php index 6ba3689..a078d35 100644 --- a/src/Constraints/HasInElement.php +++ b/src/Constraints/HasInElement.php @@ -4,22 +4,8 @@ use Symfony\Component\DomCrawler\Crawler; -class HasInElement extends PageConstraint +readonly class HasInElement extends PageConstraint { - /** - * The name or ID of the element. - * - * @var string - */ - protected $element; - - /** - * The text expected to be found. - * - * @var string - */ - protected $text; - /** * Create a new constraint instance. * @@ -27,10 +13,11 @@ class HasInElement extends PageConstraint * @param string $text * @return void */ - public function __construct($element, $text) - { - $this->text = $text; - $this->element = $element; + public function __construct( + protected string $element, + protected string $text + ) { + // } /** diff --git a/src/Constraints/HasLink.php b/src/Constraints/HasLink.php index d09cacb..25fbe79 100644 --- a/src/Constraints/HasLink.php +++ b/src/Constraints/HasLink.php @@ -5,22 +5,8 @@ use Illuminate\Support\Facades\URL; use Illuminate\Support\Str; -class HasLink extends PageConstraint +readonly class HasLink extends PageConstraint { - /** - * The text expected to be found. - * - * @var string - */ - protected $text; - - /** - * The URL expected to be linked in the tag. - * - * @var string|null - */ - protected $url; - /** * Create a new constraint instance. * @@ -28,10 +14,11 @@ class HasLink extends PageConstraint * @param string|null $url * @return void */ - public function __construct($text, $url = null) - { - $this->url = $url; - $this->text = $text; + public function __construct( + protected string $text, + protected ?string $url = null + ) { + // } /** diff --git a/src/Constraints/HasSource.php b/src/Constraints/HasSource.php index 438d6c8..6e76bdd 100644 --- a/src/Constraints/HasSource.php +++ b/src/Constraints/HasSource.php @@ -2,24 +2,18 @@ namespace Laravel\BrowserKitTesting\Constraints; -class HasSource extends PageConstraint +readonly class HasSource extends PageConstraint { - /** - * The expected HTML source. - * - * @var string - */ - protected $source; - /** * Create a new constraint instance. * * @param string $source * @return void */ - public function __construct($source) - { - $this->source = $source; + public function __construct( + protected string $source + ) { + // } /** diff --git a/src/Constraints/HasText.php b/src/Constraints/HasText.php index 5fdeb9f..fb3e844 100644 --- a/src/Constraints/HasText.php +++ b/src/Constraints/HasText.php @@ -2,24 +2,18 @@ namespace Laravel\BrowserKitTesting\Constraints; -class HasText extends PageConstraint +readonly class HasText extends PageConstraint { - /** - * The expected text. - * - * @var string - */ - protected $text; - /** * Create a new constraint instance. * * @param string $text * @return void */ - public function __construct($text) - { - $this->text = $text; + public function __construct( + protected string $text + ) { + // } /** diff --git a/src/Constraints/HasValue.php b/src/Constraints/HasValue.php index f09bcec..9d791a7 100644 --- a/src/Constraints/HasValue.php +++ b/src/Constraints/HasValue.php @@ -4,7 +4,7 @@ use Symfony\Component\DomCrawler\Crawler; -class HasValue extends FormFieldConstraint +readonly class HasValue extends FormFieldConstraint { /** * Get the valid elements. diff --git a/src/Constraints/IsChecked.php b/src/Constraints/IsChecked.php index 01c1325..f32a4d2 100644 --- a/src/Constraints/IsChecked.php +++ b/src/Constraints/IsChecked.php @@ -2,7 +2,7 @@ namespace Laravel\BrowserKitTesting\Constraints; -class IsChecked extends FormFieldConstraint +readonly class IsChecked extends FormFieldConstraint { /** * Create a new constraint instance. @@ -10,9 +10,10 @@ class IsChecked extends FormFieldConstraint * @param string $selector * @return void */ - public function __construct($selector) - { - $this->selector = $selector; + public function __construct( + protected string $selector + ) { + // } /** diff --git a/src/Constraints/IsSelected.php b/src/Constraints/IsSelected.php index d228f5b..790ed8f 100644 --- a/src/Constraints/IsSelected.php +++ b/src/Constraints/IsSelected.php @@ -5,7 +5,7 @@ use DOMElement; use Symfony\Component\DomCrawler\Crawler; -class IsSelected extends FormFieldConstraint +readonly class IsSelected extends FormFieldConstraint { /** * Get the valid elements. diff --git a/src/Constraints/PageConstraint.php b/src/Constraints/PageConstraint.php index 121724b..0b4c5f7 100644 --- a/src/Constraints/PageConstraint.php +++ b/src/Constraints/PageConstraint.php @@ -7,7 +7,7 @@ use SebastianBergmann\Comparator\ComparisonFailure; use Symfony\Component\DomCrawler\Crawler; -abstract class PageConstraint extends Constraint +abstract readonly class PageConstraint extends Constraint { /** * Make sure we obtain the HTML from the crawler or the response. diff --git a/src/Constraints/ReversePageConstraint.php b/src/Constraints/ReversePageConstraint.php index 0117a4c..467b614 100644 --- a/src/Constraints/ReversePageConstraint.php +++ b/src/Constraints/ReversePageConstraint.php @@ -2,24 +2,18 @@ namespace Laravel\BrowserKitTesting\Constraints; -class ReversePageConstraint extends PageConstraint +readonly class ReversePageConstraint extends PageConstraint { - /** - * The page constraint instance. - * - * @var \Laravel\BrowserKitTesting\Constraints\PageConstraint - */ - protected $pageConstraint; - /** * Create a new reverse page constraint instance. * * @param \Laravel\BrowserKitTesting\Constraints\PageConstraint $pageConstraint * @return void */ - public function __construct(PageConstraint $pageConstraint) - { - $this->pageConstraint = $pageConstraint; + public function __construct( + protected PageConstraint $pageConstraint + ) { + // } /** diff --git a/tests/TestCaseTest.php b/tests/TestCaseTest.php index 0ac8e72..3a250dc 100644 --- a/tests/TestCaseTest.php +++ b/tests/TestCaseTest.php @@ -15,6 +15,7 @@ public function createApplication() return new Application(); } + #[Test] public function test_refresh_application() { $this->refreshApplication(); diff --git a/tests/Unit/ImpersonatesUsersTest.php b/tests/Unit/ImpersonatesUsersTest.php index a2c2a49..a3567cb 100644 --- a/tests/Unit/ImpersonatesUsersTest.php +++ b/tests/Unit/ImpersonatesUsersTest.php @@ -5,6 +5,7 @@ use Illuminate\Contracts\Auth\Authenticatable; use Laravel\BrowserKitTesting\Concerns\ImpersonatesUsers; use Laravel\BrowserKitTesting\Tests\TestCase; +use PHPUnit\Framework\Attributes\Test; class ImpersonatesUsersTest extends TestCase { @@ -12,9 +13,7 @@ class ImpersonatesUsersTest extends TestCase protected $app; - /** - * @test - */ + #[Test] public function set_currently_logged_in_user_for_app() { $user = new class implements Authenticatable diff --git a/tests/Unit/InteractsWithAuthenticationTest.php b/tests/Unit/InteractsWithAuthenticationTest.php index c997930..64531a3 100644 --- a/tests/Unit/InteractsWithAuthenticationTest.php +++ b/tests/Unit/InteractsWithAuthenticationTest.php @@ -4,6 +4,8 @@ use Laravel\BrowserKitTesting\Concerns\InteractsWithAuthentication; use Laravel\BrowserKitTesting\Tests\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class InteractsWithAuthenticationTest extends TestCase { @@ -45,9 +47,7 @@ public function validateCredentials() }; } - /** - * @test - */ + #[Test] public function hasCredentials_return_true_if_the_credentials_are_valid() { $this->app = $this->createUserProviderToCredentials(); @@ -61,11 +61,8 @@ public function hasCredentials_return_true_if_the_credentials_are_valid() $this->assertTrue($this->hasCredentials($credentials)); } - /** - * @test - * - * @dataProvider dataHasCredentials - */ + #[Test] + #[DataProvider('dataHasCredentials')] public function hasCredentials_return_false_if_the_credentials_arent_valid($validateCredentials, $retrieveByCredentials) { $this->app = $this->createUserProviderToCredentials(); @@ -88,9 +85,7 @@ public static function dataHasCredentials() ]; } - /** - * @test - */ + #[Test] public function assert_if_credentials_are_valid_or_invalid() { $this->app = $this->createUserProviderToCredentials(); @@ -107,9 +102,7 @@ public function assert_if_credentials_are_valid_or_invalid() $this->dontSeeCredentials($credentials); } - /** - * @test - */ + #[Test] public function assert_if_user_is_authenticated() { $this->app = new class @@ -149,9 +142,7 @@ public function getAuthIdentifier() $this->seeIsAuthenticatedAs($user); } - /** - * @test - */ + #[Test] public function can_assert_if_someone_is_authenticated() { $this->app = new class @@ -181,9 +172,7 @@ public function check() $this->assertFalse($this->isAuthenticated()); } - /** - * @test - */ + #[Test] public function assert_if_someone_is_authenticated() { $this->app = new class diff --git a/tests/Unit/InteractsWithConsoleTest.php b/tests/Unit/InteractsWithConsoleTest.php index 9afe6f7..929581d 100644 --- a/tests/Unit/InteractsWithConsoleTest.php +++ b/tests/Unit/InteractsWithConsoleTest.php @@ -5,6 +5,7 @@ use Illuminate\Contracts\Console\Kernel; use Laravel\BrowserKitTesting\Concerns\InteractsWithConsole; use Laravel\BrowserKitTesting\Tests\TestCase; +use PHPUnit\Framework\Attributes\Test; class InteractsWithConsoleTest extends TestCase { @@ -12,9 +13,7 @@ class InteractsWithConsoleTest extends TestCase protected $app; - /** - * @test - */ + #[Test] public function call_artisan_command_return_code() { $this->app[Kernel::class] = new class diff --git a/tests/Unit/InteractsWithContainerTest.php b/tests/Unit/InteractsWithContainerTest.php index ada6bd0..c3ff33e 100644 --- a/tests/Unit/InteractsWithContainerTest.php +++ b/tests/Unit/InteractsWithContainerTest.php @@ -4,6 +4,7 @@ use Laravel\BrowserKitTesting\Concerns\InteractsWithContainer; use Laravel\BrowserKitTesting\Tests\TestCase; +use PHPUnit\Framework\Attributes\Test; class InteractsWithContainerTest extends TestCase { @@ -11,9 +12,7 @@ class InteractsWithContainerTest extends TestCase protected $app; - /** - * @test - */ + #[Test] public function register_instances_of_object_on_container() { $this->app = new class diff --git a/tests/Unit/InteractsWithDatabaseTest.php b/tests/Unit/InteractsWithDatabaseTest.php index 37c9cd5..93777cb 100644 --- a/tests/Unit/InteractsWithDatabaseTest.php +++ b/tests/Unit/InteractsWithDatabaseTest.php @@ -6,6 +6,7 @@ use Laravel\BrowserKitTesting\Concerns\InteractsWithConsole; use Laravel\BrowserKitTesting\Concerns\InteractsWithDatabase; use Laravel\BrowserKitTesting\Tests\TestCase; +use PHPUnit\Framework\Attributes\Test; class InteractsWithDatabaseTest extends TestCase { @@ -14,9 +15,7 @@ class InteractsWithDatabaseTest extends TestCase protected $app; - /** - * @test - */ + #[Test] public function assert_that_data_exists_on_databases() { $this->app = new class @@ -56,9 +55,7 @@ public function count() $this->seeInDatabase($table, $data); } - /** - * @test - */ + #[Test] public function assert_that_data_not_exists_on_databases() { $this->app = new class @@ -101,9 +98,7 @@ public function count() $this->notSeeInDatabase($table, $data); } - /** - * @test - */ + #[Test] public function run_seed() { $this->app[Kernel::class] = new class diff --git a/tests/Unit/InteractsWithExceptionHandlingTest.php b/tests/Unit/InteractsWithExceptionHandlingTest.php index 828dee8..1ead73d 100644 --- a/tests/Unit/InteractsWithExceptionHandlingTest.php +++ b/tests/Unit/InteractsWithExceptionHandlingTest.php @@ -9,6 +9,7 @@ use Laravel\BrowserKitTesting\Tests\Stubs\ExceptionHandlerStub; use Laravel\BrowserKitTesting\Tests\Stubs\OutputStub; use Laravel\BrowserKitTesting\Tests\TestCase; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class InteractsWithExceptionHandlingTest extends TestCase @@ -17,9 +18,7 @@ class InteractsWithExceptionHandlingTest extends TestCase protected $app; - /** - * @test - */ + #[Test] public function withExceptionHandling_restore_exception_handling() { $this->app = new Application(); @@ -31,9 +30,7 @@ public function withExceptionHandling_restore_exception_handling() ); } - /** - * @test - */ + #[Test] public function withoutExceptionHandling_disable_exception_handling_for_the_test() { $this->app = new Application(); @@ -46,9 +43,7 @@ public function withoutExceptionHandling_disable_exception_handling_for_the_test ); } - /** - * @test - */ + #[Test] public function withExceptionHandling_throw_exception_NotFoundHttpException() { $this->expectException(NotFoundHttpException::class); @@ -61,9 +56,7 @@ public function withExceptionHandling_throw_exception_NotFoundHttpException() abort(404, 'Abort 404'); } - /** - * @test - */ + #[Test] public function report_of_instance_ExceptionHandler_on_Application_does_nothing() { $this->app = new Application(); @@ -74,9 +67,7 @@ public function report_of_instance_ExceptionHandler_on_Application_does_nothing( $this->assertNull(app(ExceptionHandler::class)->report(new Exception)); } - /** - * @test - */ + #[Test] public function render_of_instance_ExceptionHandler_on_Application_throw_exception_NotFoundHttpException() { $this->expectException(NotFoundHttpException::class); @@ -108,9 +99,7 @@ public function getCode() app(ExceptionHandler::class)->render($request, new NotFoundHttpException); } - /** - * @test - */ + #[Test] public function render_of_instance_ExceptionHandler_on_Application_throw_exception_anyone() { $this->expectException(Exception::class); @@ -128,9 +117,7 @@ public function render_of_instance_ExceptionHandler_on_Application_throw_excepti app(ExceptionHandler::class)->render($request, new Exception('My Exception')); } - /** - * @test - */ + #[Test] public function renderForConsole_throw_exception_to_console_and_does_nothing() { $this->app = new Application(); @@ -145,9 +132,7 @@ public function renderForConsole_throw_exception_to_console_and_does_nothing() ); } - /** - * @test - */ + #[Test] public function withoutExceptionHandling_doesnt_not_report_exceptions() { $this->app = new Application(); diff --git a/tests/Unit/InteractsWithPagesTest.php b/tests/Unit/InteractsWithPagesTest.php index 8bc59d7..a11ae10 100644 --- a/tests/Unit/InteractsWithPagesTest.php +++ b/tests/Unit/InteractsWithPagesTest.php @@ -7,6 +7,8 @@ use Laravel\BrowserKitTesting\Concerns\InteractsWithPages; use Laravel\BrowserKitTesting\HttpException; use Laravel\BrowserKitTesting\Tests\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class InteractsWithPagesTest extends TestCase { @@ -16,9 +18,7 @@ class InteractsWithPagesTest extends TestCase protected $response; protected $currentUri; - /** - * @test - */ + #[Test] public function type_method_write_on_input() { $html = ' @@ -36,9 +36,7 @@ public function type_method_write_on_input() $this->assertSame($this->inputs['name'], $name); } - /** - * @test - */ + #[Test] public function check_method_check_checkbox() { $html = ' @@ -55,9 +53,7 @@ public function check_method_check_checkbox() $this->assertTrue($this->inputs['terms-conditions']); } - /** - * @test - */ + #[Test] public function uncheck_method_uncheck_checkbox() { $html = ' @@ -74,9 +70,7 @@ public function uncheck_method_uncheck_checkbox() $this->assertFalse($this->inputs['terms-conditions']); } - /** - * @test - */ + #[Test] public function select_method_select_an_option_from_drop_down() { $html = ' @@ -98,9 +92,7 @@ public function select_method_select_an_option_from_drop_down() $this->assertSame($this->inputs['role'], $role); } - /** - * @test - */ + #[Test] public function attach_method_attach_a_file() { $html = ' @@ -120,9 +112,7 @@ public function attach_method_attach_a_file() $this->assertSame($this->uploads['avatar'], $avatar); } - /** - * @test - */ + #[Test] public function storeInput_method_store_a_form_input_in_the_local_array() { $html = ' @@ -157,9 +147,7 @@ public function storeInput_method_store_a_form_input_in_the_local_array() $this->assertSame($this->inputs['name'], $name); } - /** - * @test - */ + #[Test] public function when_input_dont_exist_storeInput_throw_exception() { $this->expectException(InvalidArgumentException::class); @@ -181,9 +169,7 @@ public function when_input_dont_exist_storeInput_throw_exception() $this->storeInput('name', 'Taylor'); } - /** - * @test - */ + #[Test] public function getForm_method_returns_Form_from_page_with_the_given_submit_button_text() { $html = ' @@ -199,9 +185,7 @@ public function getForm_method_returns_Form_from_page_with_the_given_submit_butt $this->assertInstanceOf(\Symfony\Component\DomCrawler\Form::class, $this->getForm()); } - /** - * @test - */ + #[Test] public function when_exists_button_getForm_method_throw_exception() { $this->expectException(InvalidArgumentException::class); @@ -219,9 +203,7 @@ public function when_exists_button_getForm_method_throw_exception() $this->assertInstanceOf(\Symfony\Component\DomCrawler\Form::class, $this->getForm('Search')); } - /** - * @test - */ + #[Test] public function fillForm_method_return_Form_with_the_given_data() { $html = ' @@ -238,9 +220,7 @@ public function fillForm_method_return_Form_with_the_given_data() $this->assertSame('Taylor', $form->get('name')->getValue()); } - /** - * @test - */ + #[Test] public function fillForm_method_return_Form_when_given_array_data() { $html = ' @@ -257,9 +237,7 @@ public function fillForm_method_return_Form_when_given_array_data() $this->assertSame('Taylor', $form->get('name')->getValue()); } - /** - * @test - */ + #[Test] public function resetPageContext_method_clear_crawler_subcrawlers() { $body = ' @@ -287,9 +265,7 @@ public function resetPageContext_method_clear_crawler_subcrawlers() }); } - /** - * @test - */ + #[Test] public function clearInputs_method_clear_all_inputs_and_uploads() { $avatar = '/path/to/my-avatar.png'; @@ -305,9 +281,7 @@ public function clearInputs_method_clear_all_inputs_and_uploads() $this->assertEmpty($this->uploads); } - /** - * @test - */ + #[Test] public function extractParametersFromForm_extract_parameter_of_form() { $html = ' @@ -329,9 +303,7 @@ public function extractParametersFromForm_extract_parameter_of_form() ); } - /** - * @test - */ + #[Test] public function convertUploadsForTesting_converter_uploads_to_UploadedFile_instances() { $html = ' @@ -357,9 +329,7 @@ public function convertUploadsForTesting_converter_uploads_to_UploadedFile_insta $this->assertEmpty($uploads['photos'][0]); } - /** - * @test - */ + #[Test] public function assertPageLoaded_check_that_the_page_was_loaded() { $this->app = null; @@ -374,9 +344,7 @@ public function getStatusCode() $this->assertPageLoaded($uri); } - /** - * @test - */ + #[Test] public function assertPageLoaded_throw_exception_when_the_page_was_not_loaded_correctly() { $this->expectException(HttpException::class); @@ -394,9 +362,7 @@ public function getStatusCode() $this->assertPageLoaded($uri); } - /** - * @test - */ + #[Test] public function assertPageLoaded_throw_exception_with_response_exception() { $this->expectException(HttpException::class); @@ -421,9 +387,7 @@ public function getStatusCode() $this->assertPageLoaded($uri); } - /** - * @test - */ + #[Test] public function crawler_method_return_first_subCrawler() { $body = ' @@ -444,11 +408,8 @@ public function crawler_method_return_first_subCrawler() }); } - /** - * @test - * - * @dataProvider attributes_UploadedFile - */ + #[Test] + #[DataProvider('attributes_UploadedFile')] public function create_UploadedFile_for_testing($file, $uploads, $name) { $file = $this->getUploadedFileForTesting( @@ -490,9 +451,7 @@ public static function attributes_UploadedFile() ]; } - /** - * @test - */ + #[Test] public function getUploadedFileForTesting_return_null_if_it_can_not_upload_file() { $this->assertNull( @@ -502,9 +461,7 @@ public function getUploadedFileForTesting_return_null_if_it_can_not_upload_file( ); } - /** - * @test - */ + #[Test] public function see_on_current_HTML() { $body = ' @@ -516,9 +473,7 @@ public function see_on_current_HTML() $this->see('Hello, User'); } - /** - * @test - */ + #[Test] public function see_element_on_current_HTML() { $body = ' @@ -530,9 +485,7 @@ public function see_element_on_current_HTML() $this->seeElement('img', ['src' => 'avatar.png', 'alt' => 'ups']); } - /** - * @test - */ + #[Test] public function count_elements_on_current_HTML() { $body = ' @@ -544,9 +497,7 @@ public function count_elements_on_current_HTML() $this->seeElementCount('.card-user', 2); } - /** - * @test - */ + #[Test] public function see_text_on_current_HTML() { $body = ' @@ -558,9 +509,7 @@ public function see_text_on_current_HTML() $this->seeText('Hello, User'); } - /** - * @test - */ + #[Test] public function see_html_on_element() { $body = ' @@ -572,9 +521,7 @@ public function see_html_on_element() $this->seeInElement('h3', 'Hello, User'); } - /** - * @test - */ + #[Test] public function see_value_on_field() { $body = ' @@ -588,9 +535,7 @@ public function see_value_on_field() $this->seeInField('email', 'john.doe@testing.com'); } - /** - * @test - */ + #[Test] public function see_selected_value_on_select_tag() { $body = ' @@ -606,9 +551,7 @@ public function see_selected_value_on_select_tag() $this->seeIsSelected('role', 'sales'); } - /** - * @test - */ + #[Test] public function is_checked_checkbox() { $body = ' @@ -621,9 +564,7 @@ public function is_checked_checkbox() $this->seeIsChecked('active'); } - /** - * @test - */ + #[Test] public function see_text_on_link() { $body = ' diff --git a/tests/Unit/InteractsWithSessionTest.php b/tests/Unit/InteractsWithSessionTest.php index 9202c1a..7766074 100644 --- a/tests/Unit/InteractsWithSessionTest.php +++ b/tests/Unit/InteractsWithSessionTest.php @@ -5,6 +5,7 @@ use Illuminate\Foundation\Application; use Laravel\BrowserKitTesting\Concerns\InteractsWithSession; use Laravel\BrowserKitTesting\Tests\TestCase; +use PHPUnit\Framework\Attributes\Test; class InteractsWithSessionTest extends TestCase { @@ -12,9 +13,7 @@ class InteractsWithSessionTest extends TestCase protected $app; - /** - * @test - */ + #[Test] public function session_method_can_add_data_on_session() { $this->app['session'] = new class @@ -47,9 +46,7 @@ public function wasCalledPutMethod($times) $this->assertTrue($this->app['session']->wasCalledPutMethod(2)); } - /** - * @test - */ + #[Test] public function withSession_method_can_add_data_on_session() { $this->app['session'] = new class @@ -82,9 +79,7 @@ public function wasCalledPutMethod($times) $this->assertTrue($this->app['session']->wasCalledPutMethod(2, 'put')); } - /** - * @test - */ + #[Test] public function can_start_session() { $this->app['session'] = new class @@ -107,9 +102,7 @@ public function start() $this->assertTrue($this->app['session']->isStarted()); } - /** - * @test - */ + #[Test] public function can_flush_session() { $this->app['session'] = new class @@ -137,9 +130,7 @@ public function isCalledFlushMethod() $this->assertTrue($this->app['session']->isCalledFlushMethod()); } - /** - * @test - */ + #[Test] public function check_if_exists_data_on_session_and_check_exist_key() { $this->app['session'] = new class { @@ -163,9 +154,7 @@ public function has($key) $this->seeInSession('foo'); } - /** - * @test - */ + #[Test] public function check_multi_data_on_session_and_check_multi_keys() { $this->app['session'] = new class { @@ -201,9 +190,7 @@ public function has($key) $this->assertSessionHasAll(['foo', 'unit']); } - /** - * @test - */ + #[Test] public function check_not_exists_key_and_multi_key_on_session() { $this->app['session'] = new class { @@ -219,9 +206,7 @@ public function has($key) $this->assertSessionMissing(['foo', 'bar']); } - /** - * @test - */ + #[Test] public function check_if_exists_errors_on_session() { $this->app['session'] = new class { @@ -241,9 +226,7 @@ public function has($key) $this->assertSessionHasErrors(['foo', 'bar']); } - /** - * @test - */ + #[Test] public function check_if_exists_errors_with_value_on_session() { $this->app = new Application(); @@ -268,9 +251,7 @@ public function has($key) $this->assertSessionHasErrors(['foo' => 'bar']); } - /** - * @test - */ + #[Test] public function check_if_exists_old_input_on_session() { $this->app['session'] = new class { diff --git a/tests/Unit/MakesHttpRequestsTest.php b/tests/Unit/MakesHttpRequestsTest.php index 654d013..932d20b 100644 --- a/tests/Unit/MakesHttpRequestsTest.php +++ b/tests/Unit/MakesHttpRequestsTest.php @@ -6,6 +6,8 @@ use Laravel\BrowserKitTesting\Concerns\MakesHttpRequests; use Laravel\BrowserKitTesting\TestResponse; use Laravel\BrowserKitTesting\Tests\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\ExpectationFailedException; class MakesHttpRequestsTest extends TestCase @@ -14,11 +16,8 @@ class MakesHttpRequestsTest extends TestCase protected $baseUrl; - /** - * @test - * - * @dataProvider dataUrls - */ + #[Test] + #[DataProvider('dataUrls')] public function prepareUrlForRequest_method_return_all_url($url, $expectedUrl) { $this->baseUrl = 'http://localhost'; @@ -40,9 +39,7 @@ public static function dataUrls() ]; } - /** - * @test - */ + #[Test] public function seeStatusCode_check_status_code() { $this->response = TestResponse::fromBaseResponse(new class extends Response @@ -56,9 +53,7 @@ public function getStatusCode(): int $this->seeStatusCode(200); } - /** - * @test - */ + #[Test] public function assertResponseOk_check_that_the_status_page_should_be_200() { $this->response = TestResponse::fromBaseResponse(new class extends Response @@ -77,9 +72,7 @@ public function isOk(): bool $this->response->assertResponseOk(); } - /** - * @test - */ + #[Test] public function assertResponseOk_throw_exception_when_the_status_page_is_not_200() { $this->expectException(ExpectationFailedException::class); @@ -100,9 +93,7 @@ public function isOk(): bool $this->response->assertResponseOk(); } - /** - * @test - */ + #[Test] public function assertResponseStatus_check_the_response_status_is_equal_to_passed_by_parameter() { $this->response = TestResponse::fromBaseResponse(new class extends Response @@ -116,9 +107,7 @@ public function getStatusCode(): int $this->response->assertResponseStatus(200); } - /** - * @test - */ + #[Test] public function assertResponseStatus_throw_exception_when_the_response_status_is_not_equal_to_passed_by_parameter() { $this->expectException(ExpectationFailedException::class); @@ -134,6 +123,7 @@ public function getStatusCode(): int $this->response->assertResponseStatus(404); } + #[Test] public function testWithCookieSetCookie() { $this->withCookie('foo', 'bar'); @@ -142,6 +132,7 @@ public function testWithCookieSetCookie() $this->assertSame('bar', $this->defaultCookies['foo']); } + #[Test] public function testWithCookiesSetsCookiesAndOverwritesPreviousValues() { $this->withCookie('foo', 'bar');