1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
<?php
namespace Hamcrest\Core;
use PHPUnit\Framework\Attributes\Before;
class SetTest extends \Hamcrest\AbstractMatcherTestCase
{
public static $_classProperty;
public $_instanceProperty;
#[Before]
protected function setUpTest()
{
self::$_classProperty = null;
unset($this->_instanceProperty);
}
protected function createMatcher()
{
return \Hamcrest\Core\Set::set('property_name');
}
public function testEvaluatesToTrueIfArrayPropertyIsSet()
{
assertThat(array('foo' => 'bar'), set('foo'));
}
public function testNegatedEvaluatesToFalseIfArrayPropertyIsSet()
{
assertThat(array('foo' => 'bar'), not(notSet('foo')));
}
public function testEvaluatesToTrueIfClassPropertyIsSet()
{
self::$_classProperty = 'bar';
assertThat('Hamcrest\Core\SetTest', set('_classProperty'));
}
public function testNegatedEvaluatesToFalseIfClassPropertyIsSet()
{
self::$_classProperty = 'bar';
assertThat('Hamcrest\Core\SetTest', not(notSet('_classProperty')));
}
public function testEvaluatesToTrueIfObjectPropertyIsSet()
{
$this->_instanceProperty = 'bar';
assertThat($this, set('_instanceProperty'));
}
public function testNegatedEvaluatesToFalseIfObjectPropertyIsSet()
{
$this->_instanceProperty = 'bar';
assertThat($this, not(notSet('_instanceProperty')));
}
public function testEvaluatesToFalseIfArrayPropertyIsNotSet()
{
assertThat(array('foo' => 'bar'), not(set('baz')));
}
public function testNegatedEvaluatesToTrueIfArrayPropertyIsNotSet()
{
assertThat(array('foo' => 'bar'), notSet('baz'));
}
public function testEvaluatesToFalseIfClassPropertyIsNotSet()
{
assertThat('Hamcrest\Core\SetTest', not(set('_classProperty')));
}
public function testNegatedEvaluatesToTrueIfClassPropertyIsNotSet()
{
assertThat('Hamcrest\Core\SetTest', notSet('_classProperty'));
}
public function testEvaluatesToFalseIfObjectPropertyIsNotSet()
{
assertThat($this, not(set('_instanceProperty')));
}
public function testNegatedEvaluatesToTrueIfObjectPropertyIsNotSet()
{
assertThat($this, notSet('_instanceProperty'));
}
public function testHasAReadableDescription()
{
$this->assertDescription('set property foo', set('foo'));
$this->assertDescription('unset property bar', notSet('bar'));
}
public function testDecribesPropertySettingInMismatchMessage()
{
$this->assertMismatchDescription(
'was not set',
set('bar'),
array('foo' => 'bar')
);
$this->assertMismatchDescription(
'was "bar"',
notSet('foo'),
array('foo' => 'bar')
);
self::$_classProperty = 'bar';
$this->assertMismatchDescription(
'was "bar"',
notSet('_classProperty'),
'Hamcrest\Core\SetTest'
);
$this->_instanceProperty = 'bar';
$this->assertMismatchDescription(
'was "bar"',
notSet('_instanceProperty'),
$this
);
}
}
|