Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
namespace Hamcrest\Arrays;
3
 
4
/*
5
 Copyright (c) 2009 hamcrest.org
6
 */
7
use Hamcrest\Core\DescribedAs;
8
use Hamcrest\Core\IsNot;
9
use Hamcrest\FeatureMatcher;
10
use Hamcrest\Matcher;
11
use Hamcrest\Util;
12
 
13
/**
14
 * Matches if array size satisfies a nested matcher.
15
 */
16
class IsArrayWithSize extends FeatureMatcher
17
{
18
 
19
    public function __construct(Matcher $sizeMatcher)
20
    {
21
        parent::__construct(
22
            self::TYPE_ARRAY,
23
            null,
24
            $sizeMatcher,
25
            'an array with size',
26
            'array size'
27
        );
28
    }
29
 
30
    protected function featureValueOf($array)
31
    {
32
        return count($array);
33
    }
34
 
35
    /**
36
     * Does array size satisfy a given matcher?
37
     *
38
     * @param \Hamcrest\Matcher|int $size as a {@link Hamcrest\Matcher} or a value.
39
     *
40
     * @return \Hamcrest\Arrays\IsArrayWithSize
41
     * @factory
42
     */
43
    public static function arrayWithSize($size)
44
    {
45
        return new self(Util::wrapValueWithIsEqual($size));
46
    }
47
 
48
    /**
49
     * Matches an empty array.
50
     *
51
     * @factory
52
     */
53
    public static function emptyArray()
54
    {
55
        return DescribedAs::describedAs(
56
            'an empty array',
57
            self::arrayWithSize(0)
58
        );
59
    }
60
 
61
    /**
62
     * Matches an empty array.
63
     *
64
     * @factory
65
     */
66
    public static function nonEmptyArray()
67
    {
68
        return DescribedAs::describedAs(
69
            'a non-empty array',
70
            self::arrayWithSize(IsNot::not(0))
71
        );
72
    }
73
}