Skip to content

Commit

Permalink
Tests for SearchableRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
Padam87 committed Dec 8, 2013
1 parent 5473911 commit 1ed64b1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Tests/Models/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity()
* @ORM\Entity(repositoryClass="Padam87\SearchBundle\Tests\Models\Repository\CompanyRepository")
* @ORM\Table(name="company")
*/
class Company
Expand Down
4 changes: 3 additions & 1 deletion Tests/Models/Repository/CompanyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Padam87\SearchBundle\Tests\Models\Repository;

class CompanyRepository
use Padam87\SearchBundle\Entity\Repository\SearchableRepository;

class CompanyRepository extends SearchableRepository
{

}
43 changes: 41 additions & 2 deletions Tests/Repository/SearchableRepositoryTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,45 @@
<?php

class SearchableRepositoryTest
namespace Padam87\SearchBundle\Test\Repository;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Padam87\SearchBundle\Tests\Models\Company;

class SearchableRepositoryTest extends WebTestCase
{
public function setUp()
{
self::createClient();
}

public function testDiExtraException()
{
$em = self::$kernel->getContainer()->get('doctrine')->getManager();
$repo = $em->getRepository('Padam87SearchBundleTest:Company');

$company = new Company();

$this->assertInstanceOf('Padam87\SearchBundle\Entity\Repository\SearchableRepository', $repo);

try {
$repo->createSearchQueryBuilder($company, 'c');
} catch(\Exception $e) {
// Throws an exception every time since JMSDiExtra is not required by default
$this->assertInstanceOf('\InvalidArgumentException', $e);
}
}

public function testQueryBuilder()
{
$em = self::$kernel->getContainer()->get('doctrine')->getManager();
$service = self::$kernel->getContainer()->get('search');
$repo = $em->getRepository('Padam87SearchBundleTest:Company');
$repo->setSearchService($service);

$company = new Company();
$qb = $repo->createSearchQueryBuilder($company, 'c');

}
$this->assertInstanceOf('Padam87\SearchBundle\Entity\Repository\SearchableRepository', $repo);
$this->assertInstanceOf('Doctrine\ORM\QueryBuilder', $qb);
}
}

0 comments on commit 1ed64b1

Please sign in to comment.