ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
CrawlerAssertion.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
4
6
15{
19 protected $f = null;
20
21 public function __construct()
22 {
23 $this->f = new Factory();
24 }
25
30 public function isArray($array)
31 {
32 if (!is_array($array)) {
33 throw $this->f->exception(CrawlerException::ARRAY_EXPECTED, $array);
34 }
35 }
36
42 public function isString($string, $allow_empty = true)
43 {
44 if (!is_string($string)) {
45 if (is_array($string)) {
46 $string = json_encode($string);
47 }
48 throw $this->f->exception(CrawlerException::STRING_EXPECTED, (string) $string);
49 }
50 if (!$allow_empty && $string == "") {
51 throw $this->f->exception(CrawlerException::EMPTY_STRING, (string) $string);
52 }
53 }
54
60 public function isIndex($index, array $array)
61 {
62 if (!array_key_exists($index, $array)) {
63 throw $this->f->exception(CrawlerException::INVALID_INDEX, $index);
64 }
65 }
66
72 public function isNotIndex($index, array $array)
73 {
74 if (array_key_exists($index, $array)) {
75 throw $this->f->exception(CrawlerException::DUPLICATE_ENTRY, $index);
76 }
77 }
78
84 public function hasIndex($array, $index)
85 {
86 if (!array_key_exists($index, $array)) {
87 throw $this->f->exception(CrawlerException::MISSING_INDEX, $index);
88 }
89 }
90
96 public function isTypeOf($element, $class_name)
97 {
98 if (!get_class($element) == $class_name) {
99 throw $this->f->exception(CrawlerException::INVALID_TYPE, "Expected: " . $class_name . " got " . get_class($element));
100 }
101 }
102}
An exception for terminatinating execution or to throw for unit testing.
Tests properties and throws exceptions if not met.
$index
Definition: metadata.php:60