Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Testing\Fluent\Concerns;
4
 
5
use Illuminate\Support\Str;
6
use PHPUnit\Framework\Assert as PHPUnit;
7
 
8
trait Interaction
9
{
10
    /**
11
     * The list of interacted properties.
12
     *
13
     * @var array
14
     */
15
    protected $interacted = [];
16
 
17
    /**
18
     * Marks the property as interacted.
19
     *
20
     * @param  string  $key
21
     * @return void
22
     */
23
    protected function interactsWith(string $key): void
24
    {
25
        $prop = Str::before($key, '.');
26
 
27
        if (! in_array($prop, $this->interacted, true)) {
28
            $this->interacted[] = $prop;
29
        }
30
    }
31
 
32
    /**
33
     * Asserts that all properties have been interacted with.
34
     *
35
     * @return void
36
     */
37
    public function interacted(): void
38
    {
39
        PHPUnit::assertSame(
40
            [],
41
            array_diff(array_keys($this->prop()), $this->interacted),
42
            $this->path
43
                ? sprintf('Unexpected properties were found in scope [%s].', $this->path)
44
                : 'Unexpected properties were found on the root level.'
45
        );
46
    }
47
 
48
    /**
49
     * Disables the interaction check.
50
     *
51
     * @return $this
52
     */
53
    public function etc(): self
54
    {
55
        $this->interacted = array_keys($this->prop());
56
 
57
        return $this;
58
    }
59
 
60
    /**
61
     * Retrieve a prop within the current scope using "dot" notation.
62
     *
63
     * @param  string|null  $key
64
     * @return mixed
65
     */
66
    abstract protected function prop(string $key = null);
67
}