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;
4
 
5
use ArrayAccess;
6
use Illuminate\Testing\Constraints\ArraySubset;
7
use PHPUnit\Framework\Assert as PHPUnit;
8
use PHPUnit\Framework\Constraint\DirectoryExists;
9
use PHPUnit\Framework\Constraint\FileExists;
10
use PHPUnit\Framework\Constraint\LogicalNot;
11
use PHPUnit\Framework\Constraint\RegularExpression;
12
use PHPUnit\Framework\InvalidArgumentException;
13
 
14
/**
15
 * @internal This class is not meant to be used or overwritten outside the framework itself.
16
 */
17
abstract class Assert extends PHPUnit
18
{
19
    /**
20
     * Asserts that an array has a specified subset.
21
     *
22
     * @param  \ArrayAccess|array  $subset
23
     * @param  \ArrayAccess|array  $array
24
     * @param  bool  $checkForIdentity
25
     * @param  string  $msg
26
     * @return void
27
     */
28
    public static function assertArraySubset($subset, $array, bool $checkForIdentity = false, string $msg = ''): void
29
    {
30
        if (! (is_array($subset) || $subset instanceof ArrayAccess)) {
31
            throw InvalidArgumentException::create(1, 'array or ArrayAccess');
32
        }
33
 
34
        if (! (is_array($array) || $array instanceof ArrayAccess)) {
35
            throw InvalidArgumentException::create(2, 'array or ArrayAccess');
36
        }
37
 
38
        $constraint = new ArraySubset($subset, $checkForIdentity);
39
 
40
        PHPUnit::assertThat($array, $constraint, $msg);
41
    }
42
 
43
    /**
44
     * Asserts that a file does not exist.
45
     *
46
     * @param  string  $filename
47
     * @param  string  $message
48
     * @return void
49
     */
50
    public static function assertFileDoesNotExist(string $filename, string $message = ''): void
51
    {
52
        static::assertThat($filename, new LogicalNot(new FileExists), $message);
53
    }
54
 
55
    /**
56
     * Asserts that a directory does not exist.
57
     *
58
     * @param  string  $directory
59
     * @param  string  $message
60
     * @return void
61
     */
62
    public static function assertDirectoryDoesNotExist(string $directory, string $message = ''): void
63
    {
64
        static::assertThat($directory, new LogicalNot(new DirectoryExists), $message);
65
    }
66
 
67
    /**
68
     * Asserts that a string matches a given regular expression.
69
     *
70
     * @param  string  $pattern
71
     * @param  string  $string
72
     * @param  string  $message
73
     * @return void
74
     */
75
    public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void
76
    {
77
        static::assertThat($string, new RegularExpression($pattern), $message);
78
    }
79
}