Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fprochazka committed Sep 11, 2014
1 parent 7d0eab3 commit 48c0f06
Show file tree
Hide file tree
Showing 19 changed files with 187 additions and 139 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
},
"autoload-dev": {
"psr-0": {
"Doctrine\\Tests\\Search": "tests/"
"Doctrine\\Tests\\Search": "tests/",
"Doctrine\\Tests\\Models": "tests/"
}
}
}
4 changes: 1 addition & 3 deletions demo/ElasticSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ public static function get()
{
//Entity loader
$entities = Config::getEntityNamespacePath();
$cl = new ClassLoader($entities['namespace'], $entities['path']);
$cl->register();

//Annotation metadata driver
$config = new Configuration();
$md = $config->newDefaultAnnotationDriver(array($entities['namespace']));
$md = $config->newDefaultAnnotationDriver(array($entities['path']));
$config->setMetadataDriverImpl($md);
$config->setMetadataCacheImpl(new ArrayCache());

Expand Down
8 changes: 4 additions & 4 deletions demo/build.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

use Doctrine\Tests\Models\Comments\User;
use Doctrine\Tests\Models\Comments\Email;
use Doctrine\Tests\Models\Comments\Comment;

require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/ElasticSearch.php';

use Entities\User;
use Entities\Email;
use Entities\Comment;

$sm = ElasticSearch::get();

$client = $sm->getClient();
Expand Down
31 changes: 18 additions & 13 deletions demo/composer.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
{
"repositories":[
{
"type":"vcs",
"url":"http://github.com/doctrine/search"
}
],
"require":{
"jms/serializer":"0.15.0",
"ruflin/elastica":"v1.0.1.2",
"doctrine/search":"dev-master",
"pagerfanta/pagerfanta":"v1.0.1"
}
}
"repositories":[
{
"type":"vcs",
"url":"http://github.com/doctrine/search"
}
],
"require":{
"jms/serializer":"0.15.0",
"ruflin/elastica":"v1.0.1.2",
"doctrine/search":"dev-master",
"pagerfanta/pagerfanta":"v1.0.1"
},
"autoload-dev": {
"psr-0": {
"Doctrine\\Tests\\Models": "../tests/"
}
}
}
5 changes: 4 additions & 1 deletion demo/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public static function getServers()
//Entities namespace and location
public static function getEntityNamespacePath()
{
return array('namespace' => 'Entities', 'path' => '.');
return array(
'namespace' => 'Doctrine\Tests\Models\Comments',
'path' => __DIR__ . '/../tests/Doctrine/Tests/Models/Comments/'
);
}
}
10 changes: 5 additions & 5 deletions demo/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//Execute a direct Elastica term search
echo PHP_EOL."*** Direct Term Search ***".PHP_EOL;
$query = new Elastica\Filter\Term(array('username' => 'timmyl'));
$users = $sm->getRepository('Entities\User')->search($query);
$users = $sm->getRepository('Doctrine\Tests\Models\Comments\User')->search($query);

foreach ($users as $user) {
print_r($user);
Expand All @@ -22,7 +22,7 @@

//Execute a single term lookup, modify and persist
echo PHP_EOL."*** Single term lookup, modify and persist ***".PHP_EOL;
$user = $sm->getRepository('Entities\User')->findOneBy(array('username' => 'mrhash'));
$user = $sm->getRepository('Doctrine\Tests\Models\Comments\User')->findOneBy(array('username' => 'mrhash'));
print_r($user);
$user->setName('New name');
$sm->persist($user);
Expand All @@ -33,7 +33,7 @@
//Execute a single lookup with no results
echo PHP_EOL."*** Single lookup with no results ***".PHP_EOL;
try {
$user = $sm->find('Entities\User', 'unknownid');
$user = $sm->find('Doctrine\Tests\Models\Comments\User', 'unknownid');
} catch (Doctrine\Search\Exception\NoResultException $exception) {
print_r($exception->getMessage());
echo PHP_EOL;
Expand All @@ -51,7 +51,7 @@
'users'
));
$query->setFields(array('_source', '_parent'));
$comments = $sm->getRepository('Entities\Comment')->search($query);
$comments = $sm->getRepository('Doctrine\Tests\Models\Comments\Comment')->search($query);

foreach ($comments as $comment) {
print_r($comment);
Expand All @@ -63,7 +63,7 @@
//pass an Elastica query directly into a modified pagination adapter.
echo PHP_EOL."*** Pagerfanta paginated results ***".PHP_EOL;
$query = $sm->createQuery()
->from('Entities\Comment')
->from('Doctrine\Tests\Models\Comments\Comment')
->searchWith(new Elastica\Query())
->setQuery(new Elastica\Query\MatchAll())
->setFields(['_source', '_parent'])
Expand Down
26 changes: 3 additions & 23 deletions lib/Doctrine/Search/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class ClassMetadata implements ClassMetadataInterface
*
* @var mixed
*/
public $identifier;
public $identifier = array();


public function __construct($documentName)
Expand Down Expand Up @@ -181,31 +181,14 @@ public function __sleep()
);
}

/**
* Restores some state that can not be serialized/unserialized.
*
* @return void
*/
public function __wakeup()
{
// Restore ReflectionClass and properties
$this->reflClass = new \ReflectionClass($this->className);

foreach ($this->fieldMappings as $field => $mapping) {
$reflField = $this->reflClass->getProperty($field);
$reflField->setAccessible(true);
$this->reflFields[$field] = $reflField;
}
}

/**
* Get fully-qualified class name of this persistent class.
*
* @return string
*/
public function getName()
{
return $this->reflClass->getName();
return $this->className;

}

Expand Down Expand Up @@ -422,8 +405,6 @@ public function getIdentifierFieldNames()
// TODO: Implement getIdentifierFieldNames() method.
}



/**
* Restores some state that can not be serialized/unserialized.
*
Expand All @@ -441,8 +422,6 @@ public function wakeupReflection($reflService)
}
}



/**
* Initializes a new ClassMetadata instance that will hold the object-relational mapping
* metadata of the class with the given name.
Expand All @@ -454,5 +433,6 @@ public function wakeupReflection($reflService)
public function initializeReflection($reflService)
{
$this->reflClass = $reflService->getClass($this->className);
$this->className = $this->reflClass->getName(); // normalize classname
}
}
8 changes: 8 additions & 0 deletions lib/Doctrine/Search/SearchManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ public function getClassMetadata($className)
return $this->metadataFactory->getMetadataFor($className);
}

/**
* @return Mapping\ClassMetadataFactory
*/
public function getClassMetadataFactory()
{
return $this->metadataFactory;
}

/**
* @return SearchClientInterface
*/
Expand Down
1 change: 0 additions & 1 deletion lib/Doctrine/Search/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ final class Version
* Compare a given version with the current version
*
* @param string $version
* @param string $operator
*
* @return integer Return -1 if it older, 0 if it the same, 1 if $version is newer
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Doctrine\Tests\Search\Documents;
namespace Doctrine\Tests\Models\Blog;

use Doctrine\Search\Mapping\Annotations as SEARCH;

Expand Down Expand Up @@ -33,4 +33,4 @@ public function getName()
{
return $this->name;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Entities;
namespace Doctrine\Tests\Models\Comments;

use JMS\Serializer\Annotation as JMS;
use Doctrine\Search\Mapping\Annotations as MAP;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Entities;
namespace Doctrine\Tests\Models\Comments;

use JMS\Serializer\Annotation as JMS;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Entities;
namespace Doctrine\Tests\Models\Comments;

use JMS\Serializer\Annotation as JMS;
use Doctrine\Search\Mapping\Annotations as MAP;
Expand All @@ -21,14 +21,14 @@ class User
* as might be useful for an api.
*/
private $id;

/**
* @JMS\Type("string")
* @JMS\Expose @JMS\Groups({"api", "store"})
* @MAP\ElasticField(type="string", includeInAll=false, index="no")
*/
private $name;

/**
* @JMS\Type("string")
* @JMS\Expose @JMS\Groups({"api", "store"})
Expand All @@ -38,83 +38,83 @@ class User
* })
*/
private $username;

/**
* @JMS\Type("string")
* @JMS\Expose @JMS\Groups({"api", "store"})
* @MAP\ElasticField(type="ip", includeInAll=false, index="no", store=true, nullValue="127.0.0.1")
*/
private $ip;

/**
* @JMS\Type("array")
* @JMS\Expose @JMS\Groups({"store"})
* @MAP\ElasticField(type="string", includeInAll=false, index="not_analyzed")
*/
private $friends = array();

/**
* @JMS\Type("array<Entities\Email>")
* @JMS\Type("array<Doctrine\Tests\Models\Comments\Email>")
* @JMS\Expose @JMS\Groups({"privateapi", "store"})
* @MAP\ElasticField(type="nested", properties={
* @MAP\ElasticField(name="email", type="string", includeInAll=false, index="not_analyzed"),
* @MAP\ElasticField(name="createdAt", type="date")
* })
*/
private $emails = array();

/**
* @JMS\Type("boolean")
* @JMS\Expose @JMS\Groups({"store"})
* @MAP\ElasticField(type="boolean", nullValue=false)
*/
private $active;

public function getId()
{
if (!$this->id) {
$this->id = uniqid();
}
return $this->id;
}

public function setName($name)
{
$this->name = $name;
}

public function setUsername($username)
{
$this->username = $username;
}

public function getUsername()
{
return $this->username;
}

public function setIp($ip)
{
$this->ip = $ip;
}

public function getIp()
{
return $this->ip;
}

public function getFriends()
{
return $this->friends;
}

public function addFriend(User $user)
{
if (!in_array($user->getId(), $this->friends)) {
$this->friends[] = $user->getId();
}
}

public function addEmail(Email $email)
{
$this->emails[] = $email;
Expand Down
Loading

0 comments on commit 48c0f06

Please sign in to comment.