Nette\Collections\Hashtable test
Adding Jack
Adding invalid key
InvalidArgumentException: Key must be either a string or an integer, object given.
Adding foo
InvalidArgumentException: Item must be 'Person' object.
Adding Mary using []
InvalidArgumentException: Key must be either a string or an integer, NULL given.
Adding Mary using ['mary']
Adding Mary twice using ['mary']
Adding Mary twice using add()
InvalidStateException: An element with the same key already exists.
Adding Mary twice using __set()
MemberAccessException: Cannot assign to an undeclared property Hashtable::$mary.
Adding Jack using append
NotSupportedException:
(array):
array(2) {
"jack" => object(Person) (1) {
"name" private => string(4) "Jack"
}
"mary" => object(Person) (1) {
"name" private => string(4) "Mary"
}
}
getKeys:
array(2) {
0 => string(4) "jack"
1 => string(4) "mary"
}
Contains Jack?
bool(TRUE)
Contains Mary?
bool(TRUE)
Contains foo?
bool(FALSE)
Contains ['jim']?
bool(FALSE)
Contains ['jack']?
bool(TRUE)
Contains ['mary']?
bool(TRUE)
Contains ->jim?
bool(FALSE)
Contains ->jack?
bool(FALSE)
Contains ->mary?
bool(FALSE)
Getting ['jim']
NULL
Getting ['jim'] with throwKeyNotFound
KeyNotFoundException:
Getting ['mary']
object(Person) (1) {
"name" private => string(4) "Mary"
}
Getting ->jim
MemberAccessException: Cannot read an undeclared property Hashtable::$jim.
Getting ->mary
MemberAccessException: Cannot read an undeclared property Hashtable::$mary.
Getting get('jim')
string(7) "default"
Getting get('mary')
object(Person) (1) {
"name" private => string(4) "Mary"
}
Count: 2
Count: 2
Get Interator:
jack => My name is Jack
mary => My name is Mary
Removing Jack
bool(TRUE)
Removing Jack second time
bool(FALSE)
Removing using unset(['unknown'])
Removing using unset(->unknown)
MemberAccessException: Cannot unset the property Hashtable::$unknown.
search Jack:
bool(FALSE)
search Mary:
string(4) "mary"
Clearing
Construct from array
InvalidArgumentException: Item must be 'Person' object.
Construct from array II.
object(Hashtable) (3) {
"a" => object(Person) (1) {
"name" private => string(4) "Jack"
}
"b" => object(Person) (1) {
"name" private => string(4) "Mary"
}
"c" => object(ArrayObject) (0) {
}
}
Construct as readonly
bool(TRUE)
Adding Jack using []
NotSupportedException: Collection is read-only.
Adding Jack using add
NotSupportedException: Collection is read-only.
Removing using unset
NotSupportedException: Collection is read-only.
Changing using []
NotSupportedException: Collection is read-only.