it_can_create_an_implicit_field_rule_set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 12
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 23
rs 9.8666
1
<?php
2
3
namespace Telkins\Validation\Tests;
4
5
use Illuminate\Support\Facades\File;
6
use Illuminate\Support\Facades\Artisan;
7
8
class MakeFieldRuleSetCommandTest extends TestCase
9
{
10
    /**
11
     * @test
12
     */
13
    public function it_can_create_a_field_rule_set()
14
    {
15
        $exitCode = Artisan::call('make:field-rule-set', [
16
            'name' => 'EmailRuleSet',
17
            '--force' => true,
18
        ]);
19
20
        $this->assertEquals(0, $exitCode);
21
22
        $this->assertStringContainsString('FieldRuleSet created successfully.', Artisan::output());
23
24
        $shouldOutputFilePath = $this->app['path'] . '/Rules/FieldRuleSets/EmailRuleSet.php';
25
26
        $this->assertTrue(File::exists($shouldOutputFilePath), 'File not found in default app/Rules/FieldRuleSets folder');
27
28
        $contents = File::get($shouldOutputFilePath);
29
30
        $this->assertStringContainsString('namespace App\Rules\FieldRuleSets;', $contents);
31
32
        $this->assertStringContainsString('class EmailRuleSet extends AbstractFieldRuleSet', $contents);
33
    }
34
35
    /**
36
     * @test
37
     */
38
    public function it_can_create_an_implicit_field_rule_set()
39
    {
40
        $exitCode = Artisan::call('make:field-rule-set', [
41
            'name' => 'EmailRuleSet',
42
            '--implicit' => true,
43
            '--force' => true,
44
        ]);
45
46
        $this->assertEquals(0, $exitCode);
47
48
        $this->assertStringContainsString('FieldRuleSet created successfully.', Artisan::output());
49
50
        $shouldOutputFilePath = $this->app['path'] . '/Rules/FieldRuleSets/EmailRuleSet.php';
51
52
        $this->assertTrue(File::exists($shouldOutputFilePath), 'File not found in default app/Rules/FieldRuleSets folder');
53
54
        $contents = File::get($shouldOutputFilePath);
55
56
        $this->assertStringContainsString('namespace App\Rules\FieldRuleSets;', $contents);
57
58
        $this->assertStringContainsString('use Illuminate\Contracts\Validation\ImplicitRule;', $contents);
59
60
        $this->assertStringContainsString('class EmailRuleSet extends AbstractFieldRuleSet implements ImplicitRule', $contents);
61
    }
62
63
    /**
64
     * @test
65
     */
66
    public function it_can_create_a_field_rule_set_with_a_custom_namespace()
67
    {
68
        $exitCode = Artisan::call('make:field-rule-set', [
69
            'name' => 'MyFieldRuleSets/EmailRuleSet',
70
            '--force' => true,
71
        ]);
72
73
        $this->assertEquals(0, $exitCode);
74
75
        $this->assertStringContainsString('FieldRuleSet created successfully.', Artisan::output());
76
77
        $shouldOutputFilePath = $this->app['path'] . '/MyFieldRuleSets/EmailRuleSet.php';
78
79
        $this->assertTrue(File::exists($shouldOutputFilePath), 'File not found in custom app/MyFieldRuleSets folder');
80
81
        $contents = File::get($shouldOutputFilePath);
82
83
        $this->assertStringContainsString('namespace App\MyFieldRuleSets;', $contents);
84
85
        $this->assertStringContainsString('class EmailRuleSet extends AbstractFieldRuleSet', $contents);
86
    }
87
}
88