Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
4008b6b6
Commit
4008b6b6
authored
Mar 30, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- added arrayaccess to readonly document
- added tests for arrayaccess implementation
parent
6c4d0be6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
1 deletion
+85
-1
library/Solarium/Document/ReadOnly.php
library/Solarium/Document/ReadOnly.php
+43
-1
tests/Solarium/Document/ReadOnlyTest.php
tests/Solarium/Document/ReadOnlyTest.php
+42
-0
No files found.
library/Solarium/Document/ReadOnly.php
View file @
4008b6b6
...
...
@@ -44,7 +44,8 @@
* @package Solarium
* @subpackage Document
*/
class
Solarium_Document_ReadOnly
implements
IteratorAggregate
,
Countable
class
Solarium_Document_ReadOnly
implements
IteratorAggregate
,
Countable
,
ArrayAccess
{
/**
...
...
@@ -129,4 +130,45 @@ class Solarium_Document_ReadOnly implements IteratorAggregate, Countable
return
count
(
$this
->
_fields
);
}
/**
* ArrayAccess implementation
*
* @param miex $offset
* @param mixed $value
* @return void
*/
public
function
offsetSet
(
$offset
,
$value
)
{
$this
->
__set
(
$offset
,
$value
);
}
/**
* ArrayAccess implementation
*
* @param mixed $offset
* @return bool
*/
public
function
offsetExists
(
$offset
)
{
return
isset
(
$this
->
_fields
[
$offset
]);
}
/**
* ArrayAccess implementation
*
* @param mixed $offset
* @return void
*/
public
function
offsetUnset
(
$offset
)
{
$this
->
__set
(
$offset
,
null
);
}
/**
* ArrayAccess implementation
*
* @param mixed $offset
* @return mixed|null
*/
public
function
offsetGet
(
$offset
)
{
return
isset
(
$this
->
_fields
[
$offset
])
?
$this
->
_fields
[
$offset
]
:
null
;
}
}
\ No newline at end of file
tests/Solarium/Document/ReadOnlyTest.php
View file @
4008b6b6
...
...
@@ -83,6 +83,48 @@ class Solarium_Document_ReadOnlyTest extends PHPUnit_Framework_TestCase
$this
->
assertEquals
(
$this
->
_fields
,
$fields
);
}
public
function
testArrayGet
()
{
$this
->
assertEquals
(
$this
->
_fields
[
'categories'
],
$this
->
_doc
[
'categories'
]
);
}
public
function
testArrayGetInvalidField
()
{
$this
->
assertEquals
(
null
,
$this
->
_doc
[
'invalidfield'
]
);
}
public
function
testArrayIsset
()
{
$this
->
assertTrue
(
isset
(
$this
->
_doc
[
'categories'
])
);
}
public
function
testArrayIssetInvalidField
()
{
$this
->
assertFalse
(
isset
(
$this
->
_doc
[
'invalidfield'
])
);
}
public
function
testArraySet
()
{
$this
->
setExpectedException
(
'Solarium_Exception'
);
$this
->
_doc
[
'newField'
]
=
'new value'
;
}
public
function
testArrayUnset
()
{
$this
->
setExpectedException
(
'Solarium_Exception'
);
unset
(
$this
->
_doc
[
'newField'
]);
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
_fields
),
count
(
$this
->
_doc
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment