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

Refactor tests to pest #130

Merged
merged 3 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
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 .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction

- name: Execute tests
run: vendor/bin/phpunit
run: vendor/bin/pest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ docs
vendor
.phpunit.result.cache
.php-cs-fixer.cache
.idea
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"require-dev": {
"fakerphp/faker": "^1.9",
"orchestra/testbench": "^6.23|^7.0",
"phpunit/phpunit": "^9.4"
"phpunit/phpunit": "^9.4",
"pestphp/pest": "^1.22"
},
"autoload": {
"psr-4": {
Expand All @@ -38,7 +39,7 @@
}
},
"scripts": {
"test": "vendor/bin/phpunit"
"test": "vendor/bin/pest"
},
"extra": {
"laravel": {
Expand All @@ -51,5 +52,10 @@
}
},
"minimum-stability": "dev",
"prefer-stable": true
"prefer-stable": true,
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
}
}
102 changes: 43 additions & 59 deletions tests/AddConditionalTest.php
Original file line number Diff line number Diff line change
@@ -1,62 +1,46 @@
<?php

namespace Spatie\Menu\Laravel\Test;

use Spatie\Menu\Laravel\Menu;

class AddConditionalTest extends TestCase
{
/** @test */
public function it_adds_a_url_if_the_condition_is_true()
{
$this->assertRenders(
'<ul><li><a href="http://localhost">Home</a></li></ul>',
Menu::new()->urlIf(true, '/', 'Home')
);
}

/** @test */
public function it_doesnt_add_a_url_if_the_condition_isnt_true()
{
$this->assertRenders(
'<ul></ul>',
Menu::new()->urlIf(false, '/', 'Home')
);
}

/** @test */
public function it_adds_an_action_if_the_condition_is_true()
{
$this->assertRenders(
'<ul><li><a href="http://localhost">Home</a></li></ul>',
Menu::new()->actionIf(true, DummyController::class.'@home', 'Home')
);
}

/** @test */
public function it_doesnt_add_an_action_if_the_condition_isnt_true()
{
$this->assertRenders(
'<ul></ul>',
Menu::new()->actionIf(false, DummyController::class.'@home', 'Home')
);
}

/** @test */
public function it_adds_a_route_if_the_condition_is_true()
{
$this->assertRenders(
'<ul><li><a href="http://localhost">Home</a></li></ul>',
Menu::new()->routeIf(true, 'home', 'Home')
);
}

/** @test */
public function it_doesnt_add_a_route_if_the_condition_isnt_true()
{
$this->assertRenders(
'<ul></ul>',
Menu::new()->routeIf(false, 'home', 'Home')
);
}
}
use Spatie\Menu\Laravel\Test\DummyController;

it('adds a url if the condition is true', function () {
assertRenders(
'<ul><li><a href="http://localhost">Home</a></li></ul>',
Menu::new()->urlIf(true, '/', 'Home')
);
});

it('doesnt add a url if the condition isnt true', function () {
assertRenders(
'<ul></ul>',
Menu::new()->urlIf(false, '/', 'Home')
);
});

it('adds an action if the condition is true', function () {
assertRenders(
'<ul><li><a href="http://localhost">Home</a></li></ul>',
Menu::new()->actionIf(true, DummyController::class.'@home', 'Home')
);
});

it('doesnt add an action if the condition isnt true', function () {
assertRenders(
'<ul></ul>',
Menu::new()->actionIf(false, DummyController::class.'@home', 'Home')
);
});

it('adds a route if the condition is true', function () {
assertRenders(
'<ul><li><a href="http://localhost">Home</a></li></ul>',
Menu::new()->routeIf(true, 'home', 'Home')
);
});

it('doesnt add a route if the condition isnt true', function () {
assertRenders(
'<ul></ul>',
Menu::new()->routeIf(false, 'home', 'Home')
);
});
Loading