ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
DataFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once("vendor/composer/vendor/autoload.php");
22 
23 use ILIAS\Data;
27 
34 {
38  private ?Data\Factory $f;
39 
40  protected function setUp(): void
41  {
42  $this->f = new Data\Factory();
43  }
44 
45  protected function tearDown(): void
46  {
47  $this->f = null;
48  }
49 
50  public function testOk(): void
51  {
52  $result = $this->f->ok(3.154);
53  $this->assertInstanceOf(Data\Result::class, $result);
54  $this->assertTrue($result->isOk());
55  $this->assertFalse($result->isError());
56  }
57 
58  public function testError(): void
59  {
60  $result = $this->f->error("Something went wrong");
61  $this->assertInstanceOf(Data\Result::class, $result);
62  $this->assertTrue($result->isError());
63  $this->assertFalse($result->isOk());
64  }
65 
66  public function testPassword(): void
67  {
68  $pwd = $this->f->password("secret");
69  $this->assertInstanceOf(Data\Password::class, $pwd);
70  }
71 
72  public function testAlphanumeric(): void
73  {
74  $dataType = $this->f->alphanumeric('someValue');
75  $this->assertInstanceOf(Data\Alphanumeric::class, $dataType);
76  }
77 
78  public function testPositiveInteger(): void
79  {
80  $dataType = $this->f->positiveInteger(100);
81  $this->assertInstanceOf(Data\PositiveInteger::class, $dataType);
82  }
83 
84  public function testDataSize1(): void
85  {
86  $dataType = $this->f->dataSize(10, "MB");
87  $this->assertInstanceOf(Data\DataSize::class, $dataType);
88  }
89 
90  public function testDataSize2(): void
91  {
92  $dataType = $this->f->dataSize("10G");
93  $this->assertEquals(10, $dataType->getSize());
94  $this->assertEquals(Data\DataSize::GiB, $dataType->getUnit());
95  $this->assertEquals(10 * Data\DataSize::GiB, $dataType->inBytes());
96  $this->assertInstanceOf(Data\DataSize::class, $dataType);
97  }
98 
99  public function testLanguageTag(): void
100  {
101  $tag = $this->f->languageTag('de');
102  $this->assertInstanceOf(LanguageTag::class, $tag);
103  }
104 
105  public function testLanguageTagFailed(): void
106  {
107  $this->expectException(NotOKException::class);
108  $this->f->languageTag('d$');
109  }
110 }
Testing the faytory of result objects.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Data Factory $f