Skip to content

Commit d8c2ba6

Browse files
authored
Laravel 8 - 10 testing (#711)
1 parent 60a198a commit d8c2ba6

File tree

11 files changed

+254
-49
lines changed

11 files changed

+254
-49
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
max-parallel: 12
16+
fail-fast: false
1617
matrix:
1718
php: ['7.4', '8.0', '8.1', '8.2']
1819
package-release: [dist]
1920
steps:
2021
- name: Checkout repository
2122
uses: actions/checkout@v3
23+
with:
24+
fetch-depth: 2
2225

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

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

3336
- name: Setup Composer cache
3437
uses: actions/cache@v3
@@ -50,5 +53,5 @@ jobs:
5053
- name: Upload to Scrutinizer
5154
continue-on-error: true
5255
run: |
53-
wget https://scrutinizer-ci.com/ocular.phar
54-
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
56+
composer global require scrutinizer/ocular
57+
~/.composer/vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ composer.lock
77
coverage
88
*.taskpaper
99
NOTES.md
10-
.phpunit.result.cache
10+
/.phpunit.result.cache
11+
/.phpunit.cache/
12+
/phpunit.xml.bak
13+
/coverage.clover

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"illuminate/validation": "^6 || ^7 || ^8 || ^9 || ^10"
1717
},
1818
"require-dev": {
19-
"orchestra/testbench": "^6.13 || ^7.0"
19+
"orchestra/testbench": "^6.13 || ^7.0 || ^8"
2020
},
2121
"extra": {
2222
"branch-alias": {
@@ -35,13 +35,15 @@
3535
"psr-0": {
3636
"Kris\\LaravelFormBuilder": "src/"
3737
},
38-
"classmap": [
39-
"tests/FormBuilderTestCase.php"
40-
],
4138
"files": [
4239
"src/helpers.php"
4340
]
4441
},
42+
"autoload-dev": {
43+
"classmap": [
44+
"tests/"
45+
]
46+
},
4547
"minimum-stability": "dev",
4648
"prefer-stable": true
4749
}

phpunit.xml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="vendor/autoload.php"
5-
colors="true" convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
convertDeprecationsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
12-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
13-
>
2+
<phpunit
3+
backupGlobals="false"
4+
backupStaticProperties="false"
5+
bootstrap="vendor/autoload.php"
6+
cacheDirectory=".phpunit.cache"
7+
colors="true"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
11+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
12+
>
1413
<testsuites>
1514
<testsuite name="Package Test Suite">
1615
<directory suffix=".php">./tests/</directory>
1716
<exclude>./tests/resources/views/</exclude>
17+
<exclude>./tests/resources/lang/</exclude>
18+
<exclude>./tests/Fixtures/</exclude>
19+
<exclude>./tests/FormBuilderTestCase.php</exclude>
1820
</testsuite>
1921
</testsuites>
2022
<coverage>

tests/Fields/ButtonGroupTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@ public function it_handles_buttons(): void
104104

105105
$this->assertSame($buttons, $buttongroup->getOption('buttons'));
106106
}
107-
}
107+
}

tests/Fields/CheckableTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ public function it_handles_checked(): void
108108
$this->assertTrue($checkable->getValue());
109109
$this->assertTrue($checkable->getOption('checked'));
110110
}
111-
}
111+
}

tests/Fields/FormFieldTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ public function it_use_set_rendered()
2121
/** @test */
2222
public function it_uses_the_template_prefix()
2323
{
24-
$viewStub = $this->getMockBuilder('Illuminate\View\Factory')->setMethods(['make', 'with', 'render'])->disableOriginalConstructor()->getMock();
25-
$viewStub->method('make')->willReturn($viewStub);
26-
$viewStub->method('with')->willReturn($viewStub);
24+
$viewStub = $this->getViewFactoryMock();
2725

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

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

214212
$this->assertEquals(
215-
'The :attribute must be accepted.',
213+
'The :attribute field must be accepted.',
216214
$this->plainForm->accepted->getOption('label')
217215
);
218216
}
@@ -225,7 +223,7 @@ public function it_translates_the_label_using_translation_templates()
225223
$this->plainForm->setTranslationTemplate('validation.{name}')->add('accepted', 'text');
226224

227225
$this->assertEquals(
228-
'The :attribute must be accepted.',
226+
'The :attribute field must be accepted.',
229227
$this->plainForm->accepted->getOption('label')
230228
);
231229
}
@@ -479,7 +477,7 @@ public function label_template()
479477
'options' => [
480478
'label' => 'Text Field #1',
481479
'label_show' => true,
482-
'label_template' => 'laravel-form-builder-test::test-label',
480+
'label_template' => 'laravel-form-builder-test::test-label',
483481
]
484482
],
485483
[
@@ -488,10 +486,10 @@ public function label_template()
488486
'options' => [
489487
'label' => 'Textarea Field #1',
490488
'label_show' => true,
491-
'label_template' => 'laravel-form-builder-test::test-label',
489+
'label_template' => 'laravel-form-builder-test::test-label',
492490
]
493491
],
494-
492+
495493
];
496494

497495
foreach ($fieldsOptions as $config) {

tests/Fields/RepeatedTypeTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

3-
43
use Kris\LaravelFormBuilder\Fields\RepeatedType;
54

6-
75
class RepeatedTypeTest extends FormBuilderTestCase
86
{
97
/** @test */
@@ -55,7 +53,9 @@ public function handles_validation_rules_properly()
5553
$this->assertFalse($valid);
5654

5755
$errors = [
58-
'password' => ['The Password and password confirmation must match.'],
56+
'password' => [
57+
'The Password field must match password confirmation.',
58+
],
5959
];
6060
$this->assertEquals($errors, $plainForm->getErrors());
6161

@@ -65,7 +65,7 @@ public function handles_validation_rules_properly()
6565
'rules' => 'required|min:5',
6666
]);
6767
$plainForm->renderForm();
68-
68+
6969
$rules = ['password' => ['required', 'min:5', 'same:password_confirmation']];
7070
$this->assertEquals($rules, $plainForm->getRules());
7171

@@ -74,8 +74,8 @@ public function handles_validation_rules_properly()
7474

7575
$errors = [
7676
'password' => [
77-
'The Password must be at least 5 characters.',
78-
'The Password and password confirmation must match.',
77+
'The Password field must be at least 5 characters.',
78+
'The Password field must match password confirmation.',
7979
]
8080
];
8181
$this->assertEquals($errors, $plainForm->getErrors());
@@ -95,9 +95,9 @@ public function handles_validation_rules_properly()
9595

9696
$errors = [
9797
'password' => [
98-
'The Password must be at least 5 characters.',
99-
'The Password and password confirmation must match.',
100-
]
98+
'The Password field must be at least 5 characters.',
99+
'The Password field must match password confirmation.',
100+
]
101101
];
102102
$this->assertEquals($errors, $plainForm->getErrors());
103103

@@ -117,9 +117,9 @@ public function handles_validation_rules_properly()
117117

118118
$errors = [
119119
'password' => [
120-
'The Password must be at least 5 characters.',
121-
'The Password and password confirmation must match.',
122-
]
120+
'The Password field must be at least 5 characters.',
121+
'The Password field must match password confirmation.',
122+
]
123123
];
124124
$this->assertEquals($errors, $plainForm->getErrors());
125125
}

tests/FormBuilderTestCase.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ public function setUp(): void
186186
parent::setUp();
187187

188188
$this->withoutDeprecationHandling();
189+
190+
$this->app['path.lang'] = __DIR__ . '/resources/lang';
191+
189192
// add views for testing
190193
$this->app['view']->addNamespace('laravel-form-builder-test', __DIR__ . '/resources/views');
191194

@@ -267,4 +270,16 @@ protected function assertIdentical($one, $two): void
267270
{
268271
self::assertThat($one, new IsIdentical($two));
269272
}
273+
274+
protected function getViewFactoryMock()
275+
{
276+
$mock = $this->getMockBuilder('Illuminate\View\Factory')
277+
->onlyMethods(['make'])
278+
->addMethods(['with', 'render'])
279+
->disableOriginalConstructor()
280+
->getMock();
281+
$mock->method('make')->willReturn($mock);
282+
$mock->method('with')->willReturn($mock);
283+
return $mock;
284+
}
270285
}

tests/FormTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function it_fails_validation()
9191

9292
$errors = [
9393
'name' => ['The Name field is required.'],
94-
'description' => ['The Description must not be greater than 10 characters.']
94+
'description' => ['The Description field must not be greater than 10 characters.']
9595
];
9696

9797
$this->assertEquals($errors, $this->plainForm->getErrors());
@@ -153,7 +153,7 @@ public function it_can_automatically_redirect_back_when_failing_verification()
153153
$errorBag = $response->getSession()->get('errors');
154154
$this->assertTrue($errorBag->has('description'));
155155
$this->assertTrue($errorBag->has('name'));
156-
$this->assertEquals('The Description must not be greater than 10 characters.', $errorBag->first('description'));
156+
$this->assertEquals('The Description field must not be greater than 10 characters.', $errorBag->first('description'));
157157
}
158158
}
159159

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

@@ -233,7 +233,7 @@ public function it_overrides_default_rules_and_messages()
233233

234234
$errors = [
235235
'name' => ['Name field must be numeric.'],
236-
'description' => ['The Description must not be greater than 10 characters.'],
236+
'description' => ['The Description field must not be greater than 10 characters.'],
237237
'age' => ['The age field is a must.'],
238238
'email' => ['The email is very required.']
239239
];
@@ -1109,9 +1109,7 @@ public function it_stores_a_template_prefix()
11091109
/** @test */
11101110
public function it_uses_the_template_prefix()
11111111
{
1112-
$viewStub = $this->getMockBuilder('Illuminate\View\Factory')->setMethods(['make', 'with', 'render'])->disableOriginalConstructor()->getMock();
1113-
$viewStub->method('make')->willReturn($viewStub);
1114-
$viewStub->method('with')->willReturn($viewStub);
1112+
$viewStub = $this->getViewFactoryMock();
11151113

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

0 commit comments

Comments
 (0)