示例#1
0
 public function testShouldFormatManyAccordingToConvertMethod()
 {
     $items = ['foo', 'bar', 'baz'];
     $formatter = new MockFormatter();
     $result = $formatter->formatMany($items);
     assertThat('The result of `formatMany` should be an array of arrays.', $result, everyItem(is(typeOf('array'))));
     assertThat('The result should be the same size as the number of items passed to `formatMany`.', $result, is(arrayWithSize(count($items))));
     assertThat('The result should be correctly formatted.', $result, is(anArray([['count' => 1], ['count' => 2], ['count' => 3]])));
 }
 public function testShouldFormatTraversableAccordingToConvertMethod()
 {
     $items = ['foo', 'bar', 'baz'];
     /** @var Generator **/
     $result = (new MockFormatter())->formatTraversable(new ArrayIterator($items));
     assertThat('The result of `formatTraversable` should be a Generator.', $result, is(anInstanceOf('Generator')));
     /** @var Generator **/
     $result = (new MockFormatter())->formatTraversable(new ArrayIterator($items));
     assertThat('Every item in the result should be an array.', iterator_to_array($result), everyItem(is(typeOf('array'))));
     /** @var Generator **/
     $result = (new MockFormatter())->formatTraversable(new ArrayIterator($items));
     assertThat('The result should be the same size as the number of items passed to `formatTraversable`.', $result, is(traversableWithSize(count($items))));
     /** @var Generator **/
     $result = (new MockFormatter())->formatTraversable(new ArrayIterator($items));
     assertThat('The result should be correctly formatted.', iterator_to_array($result), is(anArray([['count' => 1], ['count' => 2], ['count' => 3]])));
 }
 public function testDescribesItself()
 {
     $each = everyItem(containsString('a'));
     $this->assertEquals('every item is a string containing "a"', (string) $each);
     $this->assertMismatchDescription('an item was "BbB"', $each, array('BbB'));
 }