Skip to content

Commit

Permalink
Laravel 8 - 10 testing (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
rudiedirkx authored Apr 19, 2023
1 parent 60a198a commit d8c2ba6
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 49 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
max-parallel: 12
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1', '8.2']
package-release: [dist]
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
Expand All @@ -28,7 +31,7 @@ jobs:

- name: Get user-level Composer cache
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Setup Composer cache
uses: actions/cache@v3
Expand All @@ -50,5 +53,5 @@ jobs:
- name: Upload to Scrutinizer
continue-on-error: true
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
composer global require scrutinizer/ocular
~/.composer/vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ composer.lock
coverage
*.taskpaper
NOTES.md
.phpunit.result.cache
/.phpunit.result.cache
/.phpunit.cache/
/phpunit.xml.bak
/coverage.clover
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"illuminate/validation": "^6 || ^7 || ^8 || ^9 || ^10"
},
"require-dev": {
"orchestra/testbench": "^6.13 || ^7.0"
"orchestra/testbench": "^6.13 || ^7.0 || ^8"
},
"extra": {
"branch-alias": {
Expand All @@ -35,13 +35,15 @@
"psr-0": {
"Kris\\LaravelFormBuilder": "src/"
},
"classmap": [
"tests/FormBuilderTestCase.php"
],
"files": [
"src/helpers.php"
]
},
"autoload-dev": {
"classmap": [
"tests/"
]
},
"minimum-stability": "dev",
"prefer-stable": true
}
26 changes: 14 additions & 12 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true" convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<phpunit
backupGlobals="false"
backupStaticProperties="false"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
colors="true"
processIsolation="false"
stopOnFailure="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
<exclude>./tests/resources/views/</exclude>
<exclude>./tests/resources/lang/</exclude>
<exclude>./tests/Fixtures/</exclude>
<exclude>./tests/FormBuilderTestCase.php</exclude>
</testsuite>
</testsuites>
<coverage>
Expand Down
2 changes: 1 addition & 1 deletion tests/Fields/ButtonGroupTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ public function it_handles_buttons(): void

$this->assertSame($buttons, $buttongroup->getOption('buttons'));
}
}
}
2 changes: 1 addition & 1 deletion tests/Fields/CheckableTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ public function it_handles_checked(): void
$this->assertTrue($checkable->getValue());
$this->assertTrue($checkable->getOption('checked'));
}
}
}
14 changes: 6 additions & 8 deletions tests/Fields/FormFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public function it_use_set_rendered()
/** @test */
public function it_uses_the_template_prefix()
{
$viewStub = $this->getMockBuilder('Illuminate\View\Factory')->setMethods(['make', 'with', 'render'])->disableOriginalConstructor()->getMock();
$viewStub->method('make')->willReturn($viewStub);
$viewStub->method('with')->willReturn($viewStub);
$viewStub = $this->getViewFactoryMock();

$helper = new FormHelper($viewStub, $this->translator, $this->config);

Expand Down Expand Up @@ -212,7 +210,7 @@ public function it_translates_the_label_if_translation_exists()
$this->plainForm->setLanguageName('validation')->add('accepted', 'text');

$this->assertEquals(
'The :attribute must be accepted.',
'The :attribute field must be accepted.',
$this->plainForm->accepted->getOption('label')
);
}
Expand All @@ -225,7 +223,7 @@ public function it_translates_the_label_using_translation_templates()
$this->plainForm->setTranslationTemplate('validation.{name}')->add('accepted', 'text');

$this->assertEquals(
'The :attribute must be accepted.',
'The :attribute field must be accepted.',
$this->plainForm->accepted->getOption('label')
);
}
Expand Down Expand Up @@ -479,7 +477,7 @@ public function label_template()
'options' => [
'label' => 'Text Field #1',
'label_show' => true,
'label_template' => 'laravel-form-builder-test::test-label',
'label_template' => 'laravel-form-builder-test::test-label',
]
],
[
Expand All @@ -488,10 +486,10 @@ public function label_template()
'options' => [
'label' => 'Textarea Field #1',
'label_show' => true,
'label_template' => 'laravel-form-builder-test::test-label',
'label_template' => 'laravel-form-builder-test::test-label',
]
],

];

foreach ($fieldsOptions as $config) {
Expand Down
24 changes: 12 additions & 12 deletions tests/Fields/RepeatedTypeTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


use Kris\LaravelFormBuilder\Fields\RepeatedType;


class RepeatedTypeTest extends FormBuilderTestCase
{
/** @test */
Expand Down Expand Up @@ -55,7 +53,9 @@ public function handles_validation_rules_properly()
$this->assertFalse($valid);

$errors = [
'password' => ['The Password and password confirmation must match.'],
'password' => [
'The Password field must match password confirmation.',
],
];
$this->assertEquals($errors, $plainForm->getErrors());

Expand All @@ -65,7 +65,7 @@ public function handles_validation_rules_properly()
'rules' => 'required|min:5',
]);
$plainForm->renderForm();

$rules = ['password' => ['required', 'min:5', 'same:password_confirmation']];
$this->assertEquals($rules, $plainForm->getRules());

Expand All @@ -74,8 +74,8 @@ public function handles_validation_rules_properly()

$errors = [
'password' => [
'The Password must be at least 5 characters.',
'The Password and password confirmation must match.',
'The Password field must be at least 5 characters.',
'The Password field must match password confirmation.',
]
];
$this->assertEquals($errors, $plainForm->getErrors());
Expand All @@ -95,9 +95,9 @@ public function handles_validation_rules_properly()

$errors = [
'password' => [
'The Password must be at least 5 characters.',
'The Password and password confirmation must match.',
]
'The Password field must be at least 5 characters.',
'The Password field must match password confirmation.',
]
];
$this->assertEquals($errors, $plainForm->getErrors());

Expand All @@ -117,9 +117,9 @@ public function handles_validation_rules_properly()

$errors = [
'password' => [
'The Password must be at least 5 characters.',
'The Password and password confirmation must match.',
]
'The Password field must be at least 5 characters.',
'The Password field must match password confirmation.',
]
];
$this->assertEquals($errors, $plainForm->getErrors());
}
Expand Down
15 changes: 15 additions & 0 deletions tests/FormBuilderTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ public function setUp(): void
parent::setUp();

$this->withoutDeprecationHandling();

$this->app['path.lang'] = __DIR__ . '/resources/lang';

// add views for testing
$this->app['view']->addNamespace('laravel-form-builder-test', __DIR__ . '/resources/views');

Expand Down Expand Up @@ -267,4 +270,16 @@ protected function assertIdentical($one, $two): void
{
self::assertThat($one, new IsIdentical($two));
}

protected function getViewFactoryMock()
{
$mock = $this->getMockBuilder('Illuminate\View\Factory')
->onlyMethods(['make'])
->addMethods(['with', 'render'])
->disableOriginalConstructor()
->getMock();
$mock->method('make')->willReturn($mock);
$mock->method('with')->willReturn($mock);
return $mock;
}
}
12 changes: 5 additions & 7 deletions tests/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function it_fails_validation()

$errors = [
'name' => ['The Name field is required.'],
'description' => ['The Description must not be greater than 10 characters.']
'description' => ['The Description field must not be greater than 10 characters.']
];

$this->assertEquals($errors, $this->plainForm->getErrors());
Expand Down Expand Up @@ -153,7 +153,7 @@ public function it_can_automatically_redirect_back_when_failing_verification()
$errorBag = $response->getSession()->get('errors');
$this->assertTrue($errorBag->has('description'));
$this->assertTrue($errorBag->has('name'));
$this->assertEquals('The Description must not be greater than 10 characters.', $errorBag->first('description'));
$this->assertEquals('The Description field must not be greater than 10 characters.', $errorBag->first('description'));
}
}

Expand Down Expand Up @@ -191,7 +191,7 @@ public function it_can_automatically_redirect_to_a_specified_destination_when_fa
$errorBag = $response->getSession()->get('errors');
$this->assertTrue($errorBag->has('description'));
$this->assertTrue($errorBag->has('name'));
$this->assertEquals('The Description must not be greater than 10 characters.', $errorBag->first('description'));
$this->assertEquals('The Description field must not be greater than 10 characters.', $errorBag->first('description'));
}
}

Expand Down Expand Up @@ -233,7 +233,7 @@ public function it_overrides_default_rules_and_messages()

$errors = [
'name' => ['Name field must be numeric.'],
'description' => ['The Description must not be greater than 10 characters.'],
'description' => ['The Description field must not be greater than 10 characters.'],
'age' => ['The age field is a must.'],
'email' => ['The email is very required.']
];
Expand Down Expand Up @@ -1109,9 +1109,7 @@ public function it_stores_a_template_prefix()
/** @test */
public function it_uses_the_template_prefix()
{
$viewStub = $this->getMockBuilder('Illuminate\View\Factory')->setMethods(['make', 'with', 'render'])->disableOriginalConstructor()->getMock();
$viewStub->method('make')->willReturn($viewStub);
$viewStub->method('with')->willReturn($viewStub);
$viewStub = $this->getViewFactoryMock();

$helper = new FormHelper($viewStub, $this->translator, $this->config);

Expand Down
Loading

0 comments on commit d8c2ba6

Please sign in to comment.