ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
DataFactoryTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2017 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3
4require_once("libs/composer/vendor/autoload.php");
5
6use ILIAS\Data;
7use PHPUnit\Framework\TestCase;
8
14class DataFactoryTest extends TestCase
15{
16
20 private $f;
21
22 protected function setUp() : void
23 {
24 $this->f = new Data\Factory();
25 }
26
27 protected function tearDown() : void
28 {
29 $this->f = null;
30 }
31
32 public function testOk()
33 {
34 $result = $this->f->ok(3.154);
35 $this->assertInstanceOf(Data\Result::class, $result);
36 $this->assertTrue($result->isOk());
37 $this->assertFalse($result->isError());
38 }
39
40 public function testError()
41 {
42 $result = $this->f->error("Something went wrong");
43 $this->assertInstanceOf(Data\Result::class, $result);
44 $this->assertTrue($result->isError());
45 $this->assertFalse($result->isOk());
46 }
47
48 public function testPassword()
49 {
50 $pwd = $this->f->password("secret");
51 $this->assertInstanceOf(Data\Password::class, $pwd);
52 }
53
54 public function testAlphanumeric()
55 {
56 $dataType = $this->f->alphanumeric('someValue');
57 $this->assertInstanceOf(Data\Alphanumeric::class, $dataType);
58 }
59
60 public function testPositiveInteger()
61 {
62 $dataType = $this->f->positiveInteger(100);
63 $this->assertInstanceOf(Data\PositiveInteger::class, $dataType);
64 }
65
66 public function testIntegerRange()
67 {
68 $dataType = $this->f->openedIntegerInterval(1, 100);
69 $this->assertInstanceOf(Data\Interval\OpenedIntegerInterval::class, $dataType);
70 }
71
72 public function testStrictIntegerRange()
73 {
74 $dataType = $this->f->closedIntegerInterval(1, 100);
75 $this->assertInstanceOf(Data\Interval\ClosedIntegerInterval::class, $dataType);
76 }
77
78 public function testFloatRange()
79 {
80 $dataType = $this->f->openedFloatInterval(1.4, 100.2);
81 $this->assertInstanceOf(Data\Interval\OpenedFloatInterval::class, $dataType);
82 }
83
84 public function testStrictFloatRange()
85 {
86 $dataType = $this->f->closedFloatInterval(1.4, 100.2);
87 $this->assertInstanceOf(Data\Interval\ClosedFloatInterval::class, $dataType);
88 }
89
90 public function testDataSize1()
91 {
92 $dataType = $this->f->dataSize(10, "MB");
93 $this->assertInstanceOf(Data\DataSize::class, $dataType);
94 }
95
96 public function testDataSize2()
97 {
98 $dataType = $this->f->dataSize("10G");
99 $this->assertEquals(10, $dataType->getSize());
100 $this->assertEquals(Data\DataSize::GiB, $dataType->getUnit());
101 $this->assertEquals(10 * Data\DataSize::GiB, $dataType->inBytes());
102 $this->assertInstanceOf(Data\DataSize::class, $dataType);
103 }
104}
$result
An exception for terminatinating execution or to throw for unit testing.
Testing the faytory of result objects.
Builds data types.
Definition: Factory.php:20