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
f415d799
Commit
f415d799
authored
Jan 27, 2014
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' of github.com:basdenooijer/solarium into develop
parents
eef3829b
81a98bde
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
561 additions
and
0 deletions
+561
-0
library/Solarium/QueryType/Update/Query/Document/Document.php
...ary/Solarium/QueryType/Update/Query/Document/Document.php
+54
-0
library/Solarium/Support/DataFixtures/Executor.php
library/Solarium/Support/DataFixtures/Executor.php
+31
-0
library/Solarium/Support/DataFixtures/FixtureInterface.php
library/Solarium/Support/DataFixtures/FixtureInterface.php
+16
-0
library/Solarium/Support/DataFixtures/FixtureLoader.php
library/Solarium/Support/DataFixtures/FixtureLoader.php
+53
-0
library/Solarium/Support/DataFixtures/Loader.php
library/Solarium/Support/DataFixtures/Loader.php
+84
-0
library/Solarium/Support/DataFixtures/Purger.php
library/Solarium/Support/DataFixtures/Purger.php
+41
-0
tests/Solarium/Tests/QueryType/Update/Query/Document/DocumentTest.php
...um/Tests/QueryType/Update/Query/Document/DocumentTest.php
+32
-0
tests/Solarium/Tests/Support/DataFixtures/ExecutorTest.php
tests/Solarium/Tests/Support/DataFixtures/ExecutorTest.php
+31
-0
tests/Solarium/Tests/Support/DataFixtures/FixtureLoaderTest.php
...Solarium/Tests/Support/DataFixtures/FixtureLoaderTest.php
+84
-0
tests/Solarium/Tests/Support/DataFixtures/Fixtures/MockFixture1.php
...rium/Tests/Support/DataFixtures/Fixtures/MockFixture1.php
+17
-0
tests/Solarium/Tests/Support/DataFixtures/Fixtures/MockFixture2.php
...rium/Tests/Support/DataFixtures/Fixtures/MockFixture2.php
+28
-0
tests/Solarium/Tests/Support/DataFixtures/LoaderTest.php
tests/Solarium/Tests/Support/DataFixtures/LoaderTest.php
+51
-0
tests/Solarium/Tests/Support/DataFixtures/PurgerTest.php
tests/Solarium/Tests/Support/DataFixtures/PurgerTest.php
+39
-0
No files found.
library/Solarium/QueryType/Update/Query/Document/Document.php
View file @
f415d799
...
...
@@ -38,6 +38,7 @@
*/
namespace
Solarium\QueryType\Update\Query\Document
;
use
Solarium\Core\Query\Helper
;
use
Solarium\QueryType\Select\Result\AbstractDocument
;
use
Solarium\Exception\RuntimeException
;
...
...
@@ -139,6 +140,15 @@ class Document extends AbstractDocument implements DocumentInterface
*/
protected
$version
;
/**
* Helper instance
*
* @var Helper
*/
protected
$helper
;
protected
$filterControlCharacters
=
true
;
/**
* Constructor
*
...
...
@@ -175,6 +185,10 @@ class Document extends AbstractDocument implements DocumentInterface
$this
->
fields
[
$key
]
=
array
(
$this
->
fields
[
$key
]);
}
if
(
$this
->
filterControlCharacters
&&
is_string
(
$value
))
{
$value
=
$this
->
getHelper
()
->
filterControlCharacters
(
$value
);
}
$this
->
fields
[
$key
][]
=
$value
;
$this
->
setFieldBoost
(
$key
,
$boost
);
if
(
$modifier
!==
null
)
{
...
...
@@ -203,6 +217,10 @@ class Document extends AbstractDocument implements DocumentInterface
if
(
$value
===
null
&&
$modifier
==
null
)
{
$this
->
removeField
(
$key
);
}
else
{
if
(
$this
->
filterControlCharacters
&&
is_string
(
$value
))
{
$value
=
$this
->
getHelper
()
->
filterControlCharacters
(
$value
);
}
$this
->
fields
[
$key
]
=
$value
;
$this
->
setFieldBoost
(
$key
,
$boost
);
if
(
$modifier
!==
null
)
{
...
...
@@ -427,4 +445,40 @@ class Document extends AbstractDocument implements DocumentInterface
{
return
$this
->
version
;
}
/**
* Get a helper instance
*
* Uses lazy loading: the helper is instantiated on first use
*
* @return Helper
*/
public
function
getHelper
()
{
if
(
null
===
$this
->
helper
)
{
$this
->
helper
=
new
Helper
(
$this
);
}
return
$this
->
helper
;
}
/**
* Whether values should be filtered for control characters automatically
*
* @param boolean $filterControlCharacters
*/
public
function
setFilterControlCharacters
(
$filterControlCharacters
)
{
$this
->
filterControlCharacters
=
$filterControlCharacters
;
}
/**
* Returns whether values should be filtered automatically or control characters
*
* @return boolean
*/
public
function
getFilterControlCharacters
()
{
return
$this
->
filterControlCharacters
;
}
}
library/Solarium/Support/DataFixtures/Executor.php
0 → 100644
View file @
f415d799
<?php
namespace
Solarium\Support\DataFixtures
;
use
Solarium\Core\Client\Client
;
/**
* @author Baldur Rensch <brensch@gmail.com>
*/
class
Executor
{
/**
* @var Client
*/
private
$client
;
public
function
__construct
(
Client
$client
)
{
$this
->
client
=
$client
;
}
/**
* @param FixtureInterface[] $fixtures
*/
public
function
execute
(
array
$fixtures
)
{
foreach
(
$fixtures
as
$fixture
)
{
$fixture
->
load
(
$this
->
client
);
}
}
}
library/Solarium/Support/DataFixtures/FixtureInterface.php
0 → 100644
View file @
f415d799
<?php
namespace
Solarium\Support\DataFixtures
;
use
Solarium\Core\Client\Client
;
/**
* @author Baldur Rensch <brensch@gmail.com>
*/
interface
FixtureInterface
{
/**
* @param Client $client
*/
public
function
load
(
Client
$client
);
}
library/Solarium/Support/DataFixtures/FixtureLoader.php
0 → 100644
View file @
f415d799
<?php
namespace
Solarium\Support\DataFixtures
;
/**
* This class is just a convenience wrapper around the fixture loading process.
*
* @author Baldur Rensch <brensch@gmail.com>
*/
class
FixtureLoader
{
/**
* @var Loader
*/
private
$loader
;
/**
* @var Purger
*/
private
$purger
;
/**
* @var Executor
*/
private
$executor
;
/**
* @param Loader $loader
* @param Purger $purger
* @param Executor $executor
*/
public
function
__construct
(
Loader
$loader
,
Purger
$purger
,
Executor
$executor
)
{
$this
->
loader
=
$loader
;
$this
->
purger
=
$purger
;
$this
->
executor
=
$executor
;
}
/**
* @param $dir
* @param bool $append
*/
public
function
loadFixturesFromDir
(
$dir
,
$append
=
true
)
{
if
(
!
$append
)
{
$this
->
purger
->
purge
();
}
$this
->
loader
->
loadFromDirectory
(
$dir
);
$this
->
executor
->
execute
(
$this
->
loader
->
getFixtures
());
}
}
library/Solarium/Support/DataFixtures/Loader.php
0 → 100644
View file @
f415d799
<?php
namespace
Solarium\Support\DataFixtures
;
/**
* @author Baldur Rensch <brensch@gmail.com>
*/
class
Loader
{
/**
* @var FixtureInterface[]
*/
private
$fixtures
;
/**
* The file extension of fixture files.
*
* @var string
*/
private
$fileExtension
=
'.php'
;
public
function
__construct
()
{
$this
->
fixtures
=
array
();
}
/**
* @param FixtureInterface $fixture
*/
public
function
addFixture
(
FixtureInterface
$fixture
)
{
$this
->
fixtures
[]
=
$fixture
;
}
/**
* @return FixtureInterface[]
*/
public
function
getFixtures
()
{
return
$this
->
fixtures
;
}
/**
* @param $dir
*
* @throws \InvalidArgumentException
*/
public
function
loadFromDirectory
(
$dir
)
{
if
(
!
is_dir
(
$dir
))
{
throw
new
\InvalidArgumentException
(
sprintf
(
'"%s" does not exist'
,
$dir
));
}
$includedFiles
=
array
();
$iterator
=
new
\RecursiveIteratorIterator
(
new
\RecursiveDirectoryIterator
(
$dir
),
\RecursiveIteratorIterator
::
LEAVES_ONLY
);
/** @var $file \DirectoryIterator */
foreach
(
$iterator
as
$file
)
{
if
((
$fileName
=
$file
->
getBasename
(
$this
->
fileExtension
))
==
$file
->
getBasename
())
{
continue
;
}
$sourceFile
=
realpath
(
$file
->
getPathName
());
/** @noinspection PhpIncludeInspection */
require_once
$sourceFile
;
$includedFiles
[]
=
$sourceFile
;
}
$declared
=
get_declared_classes
();
foreach
(
$declared
as
$className
)
{
$reflClass
=
new
\ReflectionClass
(
$className
);
$sourceFile
=
$reflClass
->
getFileName
();
if
(
in_array
(
$sourceFile
,
$includedFiles
))
{
$fixture
=
new
$className
;
$this
->
addFixture
(
$fixture
);
}
}
}
}
library/Solarium/Support/DataFixtures/Purger.php
0 → 100644
View file @
f415d799
<?php
namespace
Solarium\Support\DataFixtures
;
use
Solarium\Core\Client\Client
;
class
Purger
{
/**
* @var Client
*/
private
$client
;
/**
* @var string
*/
private
$deleteQuery
=
'*:*'
;
/**
* @param Client $client
*/
public
function
__construct
(
Client
$client
)
{
$this
->
client
=
$client
;
}
/**
* @return bool
*/
public
function
purge
()
{
$update
=
$this
->
client
->
createUpdate
();
$update
->
addDeleteQuery
(
$this
->
deleteQuery
);
$update
->
addCommit
();
$result
=
$this
->
client
->
update
(
$update
);
return
0
==
$result
->
getStatus
();
}
}
tests/Solarium/Tests/QueryType/Update/Query/Document/DocumentTest.php
View file @
f415d799
...
...
@@ -458,4 +458,36 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$this
->
doc
->
getVersion
()
);
}
public
function
testEscapeByDefaultSetField
()
{
$this
->
doc
->
setField
(
'foo'
,
'bar'
.
chr
(
15
));
$this
->
assertEquals
(
'bar '
,
$this
->
doc
->
foo
);
}
public
function
testEscapeByDefaultAddField
()
{
$this
->
doc
->
setField
(
'foo'
,
'bar'
.
chr
(
15
));
$this
->
doc
->
addField
(
'foo'
,
'bar'
.
chr
(
15
)
.
chr
(
8
));
$this
->
assertEquals
(
array
(
'bar '
,
'bar '
),
$this
->
doc
->
foo
);
}
public
function
testNoEscapeSetField
()
{
$this
->
doc
->
setFilterControlCharacters
(
false
);
$this
->
doc
->
setField
(
'foo'
,
$value
=
'bar'
.
chr
(
15
));
$this
->
assertEquals
(
$value
,
$this
->
doc
->
foo
);
}
public
function
testNoEscapeAddField
()
{
$this
->
doc
->
setFilterControlCharacters
(
false
);
$this
->
doc
->
setField
(
'foo'
,
$value1
=
'bar'
.
chr
(
15
));
$this
->
doc
->
addField
(
'foo'
,
$value2
=
'bar'
.
chr
(
15
)
.
chr
(
8
));
$this
->
assertEquals
(
array
(
$value1
,
$value2
),
$this
->
doc
->
foo
);
}
}
tests/Solarium/Tests/Support/DataFixtures/ExecutorTest.php
0 → 100644
View file @
f415d799
<?php
namespace
Solarium\Tests\Support\DataFixtures
;
use
Solarium\Support\DataFixtures\Executor
;
class
ExecutorTest
extends
\PHPUnit_Framework_TestCase
{
public
function
testLoad
()
{
$solarium
=
$this
->
getMock
(
'Solarium\Core\Client\Client'
);
$mockFixtures
=
array
(
$this
->
getMockFixture
(
$solarium
),
$this
->
getMockFixture
(
$solarium
),
);
$executor
=
new
Executor
(
$solarium
);
$executor
->
execute
(
$mockFixtures
);
}
private
function
getMockFixture
(
$client
)
{
$fixture
=
$this
->
getMock
(
'Solarium\Support\DataFixtures\FixtureInterface'
);
$fixture
->
expects
(
$this
->
once
())
->
method
(
'load'
)
->
with
(
$client
);
return
$fixture
;
}
}
tests/Solarium/Tests/Support/DataFixtures/FixtureLoaderTest.php
0 → 100644
View file @
f415d799
<?php
namespace
Solarium\Tests\Support\DataFixtures
;
use
Solarium\Support\DataFixtures\FixtureLoader
;
use
Solarium\Tests\Support\DataFixtures\Fixtures\MockFixture1
;
class
FixtureLoaderTest
extends
\PHPUnit_Framework_TestCase
{
private
$fixturePath
;
private
$client
;
public
function
testWithAppending
()
{
$loader
=
$this
->
mockLoader
();
$purger
=
$this
->
mockPurger
(
false
);
$executor
=
$this
->
mockExecutor
();
$fixtureLoader
=
new
FixtureLoader
(
$loader
,
$purger
,
$executor
);
$fixtureLoader
->
loadFixturesFromDir
(
$this
->
fixturePath
);
}
public
function
testWithPurging
()
{
$loader
=
$this
->
mockLoader
();
$purger
=
$this
->
mockPurger
(
true
);
$executor
=
$this
->
mockExecutor
();
$fixtureLoader
=
new
FixtureLoader
(
$loader
,
$purger
,
$executor
);
$fixtureLoader
->
loadFixturesFromDir
(
$this
->
fixturePath
,
false
);
}
protected
function
setUp
()
{
$this
->
client
=
$this
->
getMock
(
'Solarium\Core\Client\Client'
);
$this
->
fixturePath
=
__DIR__
.
'/Fixtures/'
;
}
private
function
mockLoader
()
{
$loader
=
$this
->
getMock
(
'Solarium\Support\DataFixtures\Loader'
,
array
(),
array
(
$this
->
client
));
$loader
->
expects
(
$this
->
once
())
->
method
(
'loadFromDirectory'
)
->
with
(
$this
->
fixturePath
);
$loader
->
expects
(
$this
->
once
())
->
method
(
'getFixtures'
)
->
will
(
$this
->
returnValue
(
array
(
$this
->
getMockFixture
()
)
)
);
return
$loader
;
}
private
function
mockPurger
(
$expectPurge
)
{
$purger
=
$this
->
getMock
(
'Solarium\Support\DataFixtures\Purger'
,
array
(),
array
(
$this
->
client
));
$purger
->
expects
(
$expectPurge
?
$this
->
once
()
:
$this
->
never
())
->
method
(
'purge'
);
return
$purger
;
}
private
function
mockExecutor
()
{
$executor
=
$this
->
getMock
(
'Solarium\Support\DataFixtures\Executor'
,
array
(),
array
(
$this
->
client
));
return
$executor
;
}
private
function
getMockFixture
()
{
return
new
MockFixture1
();
}
}
tests/Solarium/Tests/Support/DataFixtures/Fixtures/MockFixture1.php
0 → 100644
View file @
f415d799
<?php
namespace
Solarium\Tests\Support\DataFixtures\Fixtures
;
use
Solarium\Core\Client\Client
;
use
Solarium\Support\DataFixtures\FixtureInterface
;
class
MockFixture1
implements
FixtureInterface
{
/**
* @param Client $client
*/
public
function
load
(
Client
$client
)
{
// Not needed in unit test
}
}
tests/Solarium/Tests/Support/DataFixtures/Fixtures/MockFixture2.php
0 → 100644
View file @
f415d799
<?php
namespace
Solarium\Tests\Support\DataFixtures\Fixtures
;
use
Solarium\Core\Client\Client
;
use
Solarium\Support\DataFixtures\FixtureInterface
;
class
MockFixture2
implements
FixtureInterface
{
/**
* @param Client $client
*/
public
function
load
(
Client
$client
)
{
// Not needed in unit test
}
}
class
MockFixture3
implements
FixtureInterface
{
/**
* @param Client $client
*/
public
function
load
(
Client
$client
)
{
// Not needed in unit test
}
}
tests/Solarium/Tests/Support/DataFixtures/LoaderTest.php
0 → 100644
View file @
f415d799
<?php
namespace
Solarium\Tests\Support\DataFixtures
;
use
Solarium\Support\DataFixtures\Loader
;
class
LoaderTest
extends
\PHPUnit_Framework_TestCase
{
public
function
testGetEmptyFixtures
()
{
$loader
=
new
Loader
();
$this
->
assertEmpty
(
$loader
->
getFixtures
());
}
public
function
testAddFixtures
()
{
$loader
=
new
Loader
();
$fixtures
=
array
(
$this
->
getMock
(
'Solarium\Support\DataFixtures\FixtureInterface'
),
$this
->
getMock
(
'Solarium\Support\DataFixtures\FixtureInterface'
),
);
foreach
(
$fixtures
as
$fixture
)
{
$loader
->
addFixture
(
$fixture
);
}
$this
->
assertEquals
(
$fixtures
,
$loader
->
getFixtures
());
}
/**
* @expectedException \InvalidArgumentException
*/
public
function
testLoadFromInvalidDir
()
{
$loader
=
new
Loader
();
$loader
->
loadFromDirectory
(
'bla'
);
}
public
function
testLoadFromDir
()
{
$loader
=
new
Loader
();
$loader
->
loadFromDirectory
(
__DIR__
.
'/Fixtures/'
);
$loadedFixtures
=
$loader
->
getFixtures
();
$this
->
assertCount
(
3
,
$loadedFixtures
);
foreach
(
$loadedFixtures
as
$fixture
)
{
$this
->
assertInstanceOf
(
'Solarium\Support\DataFixtures\FixtureInterface'
,
$fixture
);
}
}
}
tests/Solarium/Tests/Support/DataFixtures/PurgerTest.php
0 → 100644
View file @
f415d799
<?php
namespace
Solarium\Tests\Support\DataFixtures
;
use
Solarium\Support\DataFixtures\Purger
;
class
PurgerTest
extends
\PHPUnit_Framework_TestCase
{
public
function
testPurge
()
{
$solarium
=
$this
->
getMock
(
'Solarium\Core\Client\Client'
);
$update
=
$this
->
getMock
(
'\Solarium\QueryType\Update\Query\Query'
);
$update
->
expects
(
$this
->
once
())
->
method
(
'addDeleteQuery'
)
->
with
(
'*:*'
);
$update
->
expects
(
$this
->
once
())
->
method
(
'addCommit'
);
$queryResult
=
$this
->
getMockBuilder
(
'\Solarium\QueryType\Update\Result'
)
->
disableOriginalConstructor
()
->
getMock
();
$queryResult
->
expects
(
$this
->
once
())
->
method
(
'getStatus'
)
->
will
(
$this
->
returnValue
(
0
));
$solarium
->
expects
(
$this
->
once
())
->
method
(
'createUpdate'
)
->
will
(
$this
->
returnValue
(
$update
));
$solarium
->
expects
(
$this
->
once
())
->
method
(
'update'
)
->
with
(
$update
)
->
will
(
$this
->
returnValue
(
$queryResult
));
$purger
=
new
Purger
(
$solarium
);
$purger
->
purge
();
}
}
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