ILIAS  release_7 Revision v7.30-3-g800a261c036
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 testDataSize1()
67 {
68 $dataType = $this->f->dataSize(10, "MB");
69 $this->assertInstanceOf(Data\DataSize::class, $dataType);
70 }
71
72 public function testDataSize2()
73 {
74 $dataType = $this->f->dataSize("10G");
75 $this->assertEquals(10, $dataType->getSize());
76 $this->assertEquals(Data\DataSize::GiB, $dataType->getUnit());
77 $this->assertEquals(10 * Data\DataSize::GiB, $dataType->inBytes());
78 $this->assertInstanceOf(Data\DataSize::class, $dataType);
79 }
80}
$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