ILIAS  release_8 Revision v8.24
DataFactoryTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/* Copyright (c) 2017 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see docs/LICENSE */
6
7require_once("libs/composer/vendor/autoload.php");
8
9use ILIAS\Data;
10use PHPUnit\Framework\TestCase;
11
17class DataFactoryTest extends TestCase
18{
22 private ?Data\Factory $f;
23
24 protected function setUp(): void
25 {
26 $this->f = new Data\Factory();
27 }
28
29 protected function tearDown(): void
30 {
31 $this->f = null;
32 }
33
34 public function testOk(): void
35 {
36 $result = $this->f->ok(3.154);
37 $this->assertInstanceOf(Data\Result::class, $result);
38 $this->assertTrue($result->isOk());
39 $this->assertFalse($result->isError());
40 }
41
42 public function testError(): void
43 {
44 $result = $this->f->error("Something went wrong");
45 $this->assertInstanceOf(Data\Result::class, $result);
46 $this->assertTrue($result->isError());
47 $this->assertFalse($result->isOk());
48 }
49
50 public function testPassword(): void
51 {
52 $pwd = $this->f->password("secret");
53 $this->assertInstanceOf(Data\Password::class, $pwd);
54 }
55
56 public function testAlphanumeric(): void
57 {
58 $dataType = $this->f->alphanumeric('someValue');
59 $this->assertInstanceOf(Data\Alphanumeric::class, $dataType);
60 }
61
62 public function testPositiveInteger(): void
63 {
64 $dataType = $this->f->positiveInteger(100);
65 $this->assertInstanceOf(Data\PositiveInteger::class, $dataType);
66 }
67
68 public function testDataSize1(): void
69 {
70 $dataType = $this->f->dataSize(10, "MB");
71 $this->assertInstanceOf(Data\DataSize::class, $dataType);
72 }
73
74 public function testDataSize2(): void
75 {
76 $dataType = $this->f->dataSize("10G");
77 $this->assertEquals(10, $dataType->getSize());
78 $this->assertEquals(Data\DataSize::GiB, $dataType->getUnit());
79 $this->assertEquals(10 * Data\DataSize::GiB, $dataType->inBytes());
80 $this->assertInstanceOf(Data\DataSize::class, $dataType);
81 }
82}
Testing the faytory of result objects.
Data Factory $f
Builds data types.
Definition: Factory.php:21