thecodingmachine /
tdbm
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace TheCodingMachine\TDBM; |
||||
| 4 | |||||
| 5 | use PHPUnit\Framework\TestCase; |
||||
| 6 | |||||
| 7 | use function foo\func; |
||||
| 8 | |||||
| 9 | class AbstractTDBMObjectTest extends TestCase |
||||
| 10 | { |
||||
| 11 | public function testGetManyToManyRelationshipDescriptor() |
||||
| 12 | { |
||||
| 13 | $object = new TDBMObject(); |
||||
| 14 | $this->expectException(TDBMException::class); |
||||
| 15 | $this->expectExceptionMessage('Could not find many to many relationship descriptor key for "foo"'); |
||||
| 16 | $object->_getManyToManyRelationshipDescriptor('foo'); |
||||
| 17 | } |
||||
| 18 | |||||
| 19 | public function testEmptyResultIterator() |
||||
| 20 | { |
||||
| 21 | $a = ResultIterator::createEmpyIterator(); |
||||
| 22 | foreach ($a as $empty) { |
||||
| 23 | throw new \LogicException("Not supposed to iterate on an empty iterator."); |
||||
| 24 | } |
||||
| 25 | $this->assertEquals(0, $a->count()); |
||||
| 26 | $this->assertEquals(null, $a->first()); |
||||
| 27 | $this->assertEquals(null, isset($a[0])); //an empty resultIterator must implement arrayAccess |
||||
| 28 | $this->assertEquals([], $a->toArray()); |
||||
| 29 | foreach ($a->map(function ($foo) { |
||||
|
0 ignored issues
–
show
|
|||||
| 30 | }) as $empty) { |
||||
| 31 | throw new \LogicException("Not supposed to iterate on an empty iterator."); |
||||
| 32 | } |
||||
| 33 | $c = $a->withOrder("who cares"); |
||||
| 34 | foreach ($c as $empty) { |
||||
| 35 | throw new \LogicException("Not supposed to iterate on an empty iterator."); |
||||
| 36 | } |
||||
| 37 | $this->assertEquals(0, $c->count()); |
||||
| 38 | $d = $a->withParameters(["who cares"]); |
||||
| 39 | foreach ($d as $empty) { |
||||
| 40 | throw new \LogicException("Not supposed to iterate on an empty iterator."); |
||||
| 41 | } |
||||
| 42 | $this->assertEquals(0, $d->count()); |
||||
| 43 | } |
||||
| 44 | |||||
| 45 | public function testEmptyPageIterator() |
||||
| 46 | { |
||||
| 47 | $a = ResultIterator::createEmpyIterator(); |
||||
| 48 | $b = $a->take(0, 10); |
||||
| 49 | foreach ($b as $empty) { |
||||
| 50 | throw new \LogicException("Not supposed to iterate on an empty page iterator."); |
||||
| 51 | } |
||||
| 52 | $this->assertEquals(0, $b->count()); |
||||
| 53 | $this->assertEquals([], $b->toArray()); |
||||
| 54 | $this->assertEquals(0, $b->totalCount()); |
||||
| 55 | $c = $b->map(function ($foo) { |
||||
|
0 ignored issues
–
show
The parameter
$foo is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 56 | }); |
||||
| 57 | foreach ($c as $empty) { |
||||
| 58 | throw new \LogicException("Not supposed to iterate on an empty iterator."); |
||||
| 59 | } |
||||
| 60 | $this->assertEquals([], $c->toArray()); |
||||
| 61 | } |
||||
| 62 | } |
||||
| 63 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.