Skip to content

Commit

Permalink
Added a functional test for issue schmittjoh#219.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adirelle committed Dec 22, 2015
1 parent e2181b8 commit 15f74d3
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Tests/Functional/Entities/TestEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace JMS\DiExtraBundle\Tests\Functional\Entities;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity(repositoryClass="\JMS\DiExtraBundle\Tests\Functional\Entities\TestEntityRepository")
*/
class TestEntity
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
*/
private $id;
}
43 changes: 43 additions & 0 deletions Tests/Functional/Entities/TestEntityRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace JMS\DiExtraBundle\Tests\Functional\Entities;

use Doctrine\ORM\EntityRepository;
use JMS\DiExtraBundle\Annotation as DI;

class TestEntityRepository extends EntityRepository
{
private $service;

private $parameter;

public function getService()
{
return $this->service;
}

public function getParameter()
{
return $this->parameter;
}

/**
* @DI\InjectParams({
* "service" = @DI\Inject("some_service")
* })
*/
public function setService($service)
{
$this->service = $service;
}

/**
* @DI\InjectParams({
* "parameter" = @DI\Inject("foo_%some_parameter%")
* })
*/
public function setParameter($parameter)
{
$this->parameter = $parameter;
}
}
18 changes: 18 additions & 0 deletions Tests/Functional/Issue219Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace JMS\DiExtraBundle\Tests\Functional;

class Issue219Test extends BaseTestCase
{
public function testDoctrineRepositoryInjection()
{
$kernel = static::createKernel(array('debug' => false, 'config' => 'issue-219.yml'));
$kernel->boot();

$manager = $kernel->getContainer()->get('doctrine.orm.default_entity_manager');
$repository = $manager->getRepository('\JMS\DiExtraBundle\Tests\Functional\Entities\TestEntity');

$this->assertSame($kernel->getContainer()->get('some_service'), $repository->getService());
$this->assertEquals("foo_42", $repository->getParameter());
}
}
17 changes: 17 additions & 0 deletions Tests/Functional/config/issue-219.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
imports:
- { resource: doctrine.yml }

doctrine:
orm:
mappings:
test_entities:
type: annotation
dir: %kernel.root_dir%/Entities
prefix: JMS\DiExtraBundle\Tests\Functional\Entities

services:
some_service:
class: stdClass

parameters:
some_parameter: 42

0 comments on commit 15f74d3

Please sign in to comment.