19548cd79df2eeb436673b14ed50ea09bb3a4ed9
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Database / EmptyStatementTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Database;
4
5 use Drupal\Core\Database\StatementEmpty;
6 use Drupal\Core\Database\StatementInterface;
7 use Drupal\Tests\UnitTestCase;
8
9 /**
10  * Tests the empty pseudo-statement class.
11  *
12  * @group Database
13  */
14 class EmptyStatementTest extends UnitTestCase {
15   /**
16    * Tests that the empty result set behaves as empty.
17    */
18   public function testEmpty() {
19     $result = new StatementEmpty();
20
21     $this->assertTrue($result instanceof StatementInterface, 'Class implements expected interface');
22     $this->assertNull($result->fetchObject(), 'Null result returned.');
23   }
24
25   /**
26    * Tests that the empty result set iterates safely.
27    */
28   public function testEmptyIteration() {
29     $result = new StatementEmpty();
30     $this->assertSame(0, iterator_count($result), 'Empty result set should not iterate.');
31   }
32
33   /**
34    * Tests that the empty result set mass-fetches in an expected way.
35    */
36   public function testEmptyFetchAll() {
37     $result = new StatementEmpty();
38
39     $this->assertEquals($result->fetchAll(), [], 'Empty array returned from empty result set.');
40   }
41
42 }