コード例 #1
0
 public function testShouldBeCallableThatCallsProcessMethod()
 {
     $processor = new MockProcessor();
     assertThat('The processor is a callable.', $processor, is(callableValue()));
     $result = $processor(['foo' => 'bar'], 'foo');
     // The mock processor just returns the input data array.
     assertThat('The result of processor should be the same as the input.', $result, is(anArray(['foo' => 'bar'])));
     assertThat('The processor should be able to make use of the item being formatted.', $processor->getLatestItem(), is('foo'));
 }
コード例 #2
0
 public function testValidateRunsAllValidators()
 {
     $dataValidator = new DataValidator();
     $dataValidator->addValidator(function (array $data) {
         return 'always_fail_one';
     });
     $dataValidator->addValidator(function (array $data) {
         return 'always_fail_two';
     });
     assertThat('`validate` should run the data against each registered validator.', $dataValidator->validate([1, 2, 3]), is(anArray(['always_fail_one' => true, 'always_fail_two' => true])));
 }
コード例 #3
0
 public function testFormatManyShouldApplyProcessors()
 {
     $items = ['foo', 'bar', 'baz'];
     $formatter = new MockFormatter();
     $formatter->addProcessor(function (array $data, $item) {
         $data[$item] = true;
         return $data;
     });
     $result = $formatter->formatMany($items);
     $expected = [['count' => 1, 'foo' => true], ['count' => 2, 'bar' => true], ['count' => 3, 'baz' => true]];
     assertThat('The formatter should correctly apply the processors.', $result, is(anArray($expected)));
 }
コード例 #4
0
 public function testProcessAppliesAllProcessors()
 {
     $dataValidator = new DataValidator();
     $dataValidator->addProcessor(function (array $data) {
         $data['one'] = 1;
         return $data;
     });
     $dataValidator->addProcessor(function (array $data) {
         $data['two'] = 2;
         return $data;
     });
     assertThat('`process` should apply all registered processors to the given data array.', $dataValidator->process([]), is(anArray(['one' => 1, 'two' => 2])));
 }
コード例 #5
0
 public function testDoesNotMatchAnAssociativeArrayWhenKeysDoNotMatch()
 {
     $this->assertDoesNotMatch(anArray(array('x' => equalTo('a'), 'y' => equalTo('b'))), array('x' => 'b', 'z' => 'c'), 'should not match array with different keys');
 }
コード例 #6
0
 function testFlattenHighlightWithOverlappingEntriesThatHaveEqualEnd()
 {
     $highlight1 = new Highlight(5, 10, Highlight::MATCH, 'ref1', 0, 0);
     $highlight2 = new Highlight(7, 10, Highlight::ADDED, 'ref2', 0, 0);
     $highlights = array($highlight1, $highlight2);
     $this->highlight->flattenHighlights($highlights);
     assertThat($highlights, anArray(array(new Highlight(5, 10, Highlight::UNDEFINED, 'ref1', 0, 0))));
 }
コード例 #7
0
 /**
  * @expectedException PHPUnit_Framework_Error
  * @expectedExceptionCode E_USER_ERROR
  */
 function testCannotBridgeFinalType()
 {
     HamcrestTypeBridge::argOfTypeThat('PhockitoHamcrestTypeBridgeTest_MockMe_Final', anArray());
 }
コード例 #8
0
 /**
  * @expectedException PHPUnit_Framework_Error
  * @expectedExceptionCode E_USER_ERROR
  */
 function testCannotBridgeFinalType()
 {
     HamcrestTypeBridge::argOfTypeThat(FinalClass::class, anArray());
 }