Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marcus Eibrink-Lunzenauer
Stud.IP
Commits
09e2bf5a
Commit
09e2bf5a
authored
6 months ago
by
Jan-Hendrik Willms
Browse files
Options
Downloads
Patches
Plain Diff
fix unserialization of StudipArrayObjects, remove deprecated Serializable...
Closes #4537 Merge request
studip/studip!3333
parent
353d62ab
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/classes/StudipArrayObject.php
+3
-42
3 additions, 42 deletions
lib/classes/StudipArrayObject.php
tests/unit/lib/classes/StudipArrayObjectTest.php
+131
-0
131 additions, 0 deletions
tests/unit/lib/classes/StudipArrayObjectTest.php
with
134 additions
and
42 deletions
lib/classes/StudipArrayObject.php
+
3
−
42
View file @
09e2bf5a
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
*/
class
StudipArrayObject
implements
IteratorAggregate
,
ArrayAccess
,
Serializable
,
Countable
class
StudipArrayObject
implements
IteratorAggregate
,
ArrayAccess
,
Countable
{
{
/**
/**
* Properties of the object have their normal functionality
* Properties of the object have their normal functionality
...
@@ -147,6 +147,8 @@ class StudipArrayObject implements IteratorAggregate, ArrayAccess, Serializable,
...
@@ -147,6 +147,8 @@ class StudipArrayObject implements IteratorAggregate, ArrayAccess, Serializable,
*/
*/
public
function
__unserialize
(
array
$data
):
void
public
function
__unserialize
(
array
$data
):
void
{
{
$this
->
protectedProperties
=
array_keys
(
get_object_vars
(
$this
));
foreach
(
$data
as
$k
=>
$v
)
{
foreach
(
$data
as
$k
=>
$v
)
{
switch
(
$k
)
{
switch
(
$k
)
{
case
'flag'
:
case
'flag'
:
...
@@ -344,16 +346,6 @@ class StudipArrayObject implements IteratorAggregate, ArrayAccess, Serializable,
...
@@ -344,16 +346,6 @@ class StudipArrayObject implements IteratorAggregate, ArrayAccess, Serializable,
}
}
}
}
/**
* Serialize an ArrayObject
*
* @return string
*/
public
function
serialize
()
{
return
serialize
(
get_object_vars
(
$this
));
}
/**
/**
* Sets the behavior flags
* Sets the behavior flags
*
*
...
@@ -417,37 +409,6 @@ class StudipArrayObject implements IteratorAggregate, ArrayAccess, Serializable,
...
@@ -417,37 +409,6 @@ class StudipArrayObject implements IteratorAggregate, ArrayAccess, Serializable,
}
}
}
}
/**
* Unserialize an ArrayObject
*
* @param string $data
* @return void
*/
public
function
unserialize
(
$data
)
{
$ar
=
unserialize
(
$data
);
$this
->
setFlags
(
$ar
[
'flag'
]);
$this
->
exchangeArray
(
$ar
[
'storage'
]);
$this
->
setIteratorClass
(
$ar
[
'iteratorClass'
]);
foreach
(
$ar
as
$k
=>
$v
)
{
switch
(
$k
)
{
case
'flag'
:
$this
->
setFlags
(
$v
);
break
;
case
'storage'
:
$this
->
exchangeArray
(
$v
);
break
;
case
'iteratorClass'
:
$this
->
setIteratorClass
(
$v
);
break
;
case
'protectedProperties'
:
break
;
default
:
$this
->
__set
(
$k
,
$v
);
}
}
}
/**
/**
* Validates whether the given key is a protected property.
* Validates whether the given key is a protected property.
*
*
...
...
This diff is collapsed.
Click to expand it.
tests/unit/lib/classes/StudipArrayObjectTest.php
0 → 100644
+
131
−
0
View file @
09e2bf5a
<?php
/**
* @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
* @license GPL2 or any later version
*
* @covers StudipArrayObject
*/
class
StudipArrayObjectTest
extends
\Codeception\Test\Unit
{
/**
* @covers StudipArrayObject::__construct
*/
public
function
testCreation
()
{
$array
=
new
StudipArrayObject
();
$this
->
assertCount
(
0
,
$array
);
}
/**
* @covers StudipArrayObject::__construct
*/
public
function
testCreationWithData
()
{
$array
=
new
StudipArrayObject
([
'foo'
=>
'bar'
,
42
=>
23
]);
$this
->
assertCount
(
2
,
$array
);
return
$array
;
}
/**
* @covers StudipArrayObject::__construct
*/
public
function
testCreationWithInvalidIteratorClass
()
{
$this
->
expectException
(
InvalidArgumentException
::
class
);
$array
=
new
StudipArrayObject
([],
StudipArrayObject
::
STD_PROP_LIST
,
'DefinitelyNotAnIteratorClass'
);
}
/**
* @depends testCreationWithData
* @covers StudipArrayObject::offsetExists
* @covers StudipArrayObject::offsetGet
* @covers StudipArrayObject::offsetSet
* @covers StudipArrayObject::offsetUnset
*/
public
function
testArrayAccess
(
StudipArrayObject
$array
)
{
$this
->
assertTrue
(
isset
(
$array
[
'foo'
]));
$this
->
assertFalse
(
isset
(
$array
[
'bar'
]));
$this
->
assertEquals
(
'bar'
,
$array
[
'foo'
]);
$this
->
assertEquals
(
23
,
$array
[
42
]);
$array
[
'bar'
]
=
'foo'
;
$this
->
assertCount
(
3
,
$array
);
$this
->
assertTrue
(
isset
(
$array
[
'bar'
]));
$this
->
assertEquals
(
'foo'
,
$array
[
'bar'
]);
unset
(
$array
[
'bar'
]);
$this
->
assertCount
(
2
,
$array
);
$this
->
assertFalse
(
isset
(
$array
[
'bar'
]));
}
/**
* @depends testCreationWithData
* @covers StudipArrayObject::setFlags
* @covers StudipArrayObject::__isset
* @covers StudipArrayObject::__get
* @covers StudipArrayObject::__set
* @covers StudipArrayObject::__unset
*/
public
function
testObjectAccess
(
StudipArrayObject
$array
)
{
$array
->
setFlags
(
StudipArrayObject
::
ARRAY_AS_PROPS
);
$this
->
assertTrue
(
isset
(
$array
->
foo
));
$this
->
assertFalse
(
isset
(
$array
->
bar
));
$this
->
assertEquals
(
'bar'
,
$array
->
foo
);
$array
->
bar
=
'foo'
;
$this
->
assertCount
(
3
,
$array
);
$this
->
assertTrue
(
isset
(
$array
->
bar
));
$this
->
assertEquals
(
'foo'
,
$array
->
bar
);
unset
(
$array
->
bar
);
$this
->
assertCount
(
2
,
$array
);
$this
->
assertFalse
(
isset
(
$array
->
bar
));
$array
->
setFlags
(
StudipArrayObject
::
STD_PROP_LIST
);
$this
->
expectException
(
InvalidArgumentException
::
class
);
$test
=
isset
(
$array
->
storage
);
}
public
function
testAppend
()
{
$array
=
new
StudipArrayObject
();
$this
->
assertCount
(
0
,
$array
);
$array
->
append
(
'foo'
);
$this
->
assertCount
(
1
,
$array
);
}
public
function
testContains
()
{
$array
=
new
StudipArrayObject
([
1
,
2
,
3
]);
$this
->
assertTrue
(
$array
->
contains
(
1
));
$this
->
assertFalse
(
$array
->
contains
(
0
));
}
public
function
testSerialization
()
{
$array
=
new
StudipArrayObject
();
$array
->
foo
=
'bar'
;
$serialized
=
serialize
(
$array
);
$unserialized
=
unserialize
(
$serialized
);
$this
->
assertNotFalse
(
$unserialized
);
$this
->
assertTrue
(
isset
(
$unserialized
->
foo
));
$this
->
assertEquals
(
'bar'
,
$unserialized
->
foo
);
$this
->
expectException
(
InvalidArgumentException
::
class
);
$test
=
isset
(
$unserialized
->
storage
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment