Skip to content

Commit

Permalink
add trest for routable trait
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Nov 19, 2019
1 parent f82c288 commit a723452
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
34 changes: 34 additions & 0 deletions TestCases/Content/RoutableTestCaseTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ContentBundle\TestCases\Content;

use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\RoutableInterface;

/**
* Trait to test your implementation of the TemplateInterface.
*/
trait RoutableTestCaseTrait
{
abstract protected function getRoutableInstance(DimensionInterface $dimension): RoutableInterface;

public function testGetLocale(): void
{
$dimension = $this->prophesize(DimensionInterface::class);
$dimension->getLocale()->willReturn('en');

$model = $this->getRoutableInstance($dimension->reveal());
$this->assertSame('en', $model->getLocale());
}
}
57 changes: 57 additions & 0 deletions Tests/Unit/Content/Domain/Model/RoutableTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ContentBundle\Tests\Unit\Content\Domain\Model;

use PHPUnit\Framework\TestCase;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\RoutableInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\RoutableTrait;
use Sulu\Bundle\ContentBundle\TestCases\Content\RoutableTestCaseTrait;

class RoutableTraitTest extends TestCase
{
use RoutableTestCaseTrait;

protected function getRoutableInstance(DimensionInterface $dimension): RoutableInterface
{
return new class($dimension) implements RoutableInterface {
use RoutableTrait;

/**
* @var DimensionInterface
*/
private $dimension;

public function __construct(DimensionInterface $dimension)
{
$this->dimension = $dimension;
}

public function getContentClass(): string
{
return \get_class($this);
}

public function getContentId()
{
return 1;
}

public function getDimension(): DimensionInterface
{
return $this->dimension;
}
};
}
}

0 comments on commit a723452

Please sign in to comment.