Пример #1
0
            $exceptionThrown = false;
            try {
                $matcher = new LengthMatcher(2);
                $matcher->match(1);
            } catch (\Exception $exception) {
                $exceptionThrown = true;
            }
            if (!$exceptionThrown) {
                throw new \Exception('Does not throw an exception');
            }
        });
    });
    context('getFailureMessage', function () {
        it('lists the expected length', function () {
            $matcher = new LengthMatcher(2);
            $matcher->match('pho');
            $expected = 'Expected string to have a length of 2';
            if ($expected !== $matcher->getFailureMessage()) {
                throw new \Exception('Did not return expected failure message');
            }
        });
        it('lists the expected length with inversed logic', function () {
            $matcher = new LengthMatcher(3);
            $matcher->match(array('a', 'b', 'c'));
            $expected = 'Expected array not to have a length of 3';
            if ($expected !== $matcher->getFailureMessage(true)) {
                throw new \Exception('Did not return expected failure message');
            }
        });
    });
});
Пример #2
0
            $exceptionThrown = false;
            try {
                $matcher = new LengthMatcher(2);
                $matcher->match(1);
            } catch (\Exception $exception) {
                $exceptionThrown = true;
            }
            if (!$exceptionThrown) {
                throw new \Exception('Does not throw an exception');
            }
        });
    });
    context('getFailureMessage', function () {
        it('lists the expected length', function () {
            $matcher = new LengthMatcher(2);
            $matcher->match('pho');
            $expected = 'Expected string to have a length of 2';
            if ($expected !== $matcher->getFailureMessage()) {
                throw new \Exception('Did not return expected failure message');
            }
        });
        it('lists the expected length with negated logic', function () {
            $matcher = new LengthMatcher(3);
            $matcher->match(['a', 'b', 'c']);
            $expected = 'Expected array not to have a length of 3';
            if ($expected !== $matcher->getFailureMessage(true)) {
                throw new \Exception('Did not return expected failure message');
            }
        });
    });
});