Skip to content

Commit

Permalink
Unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
manuxi committed Mar 26, 2021
1 parent fd41ab5 commit 39104b5
Show file tree
Hide file tree
Showing 10 changed files with 495 additions and 22 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SuluEventBundle!
This bundle was made based on pr of https://github.com/sulu/sulu-workshop.
I made it to quickly install it in my projects.
I made it to quickly install those entities in my projects.
This bundle is still in development. Use at own risk :)

## Installation
Install the package with:
Expand All @@ -14,7 +15,7 @@ Manuxi\SuluEventBundle\SuluEventBundle::class => ['all' => true],
```
Please add the following to your `routes_admin.yaml`:
```yaml
sulu_event.admin:
SuluEventBundle:
resource: '@SuluEventBundle/Resources/config/routes_admin.yml'
```
...and the following to your `routes_website.yaml`:
Expand Down
17 changes: 10 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
"authors": [
{
"name": "Manuel Bertrams",
"email": "[email protected]"
"email": "[email protected]"
}
],
"require": {
"cocur/slugify": "^4.0",
"dantleech/phpcr-migrations-bundle": "^1.2",
"php": "^7.1.3",
"sulu/sulu": "^2.2",
Expand All @@ -18,15 +19,14 @@
"symfony/framework-bundle": "^4.0 | ^5.0",
"symfony/http-foundation": "^4.0 | ^5.0",
"symfony/http-kernel": "^4.0 | ^5.0",
"cocur/slugify": "^4.0",
"symfony/translation": "^5.2",
"symfony/intl": "^5.2"
"symfony/intl": "^5.2",
"symfony/translation": "^5.2"
},
"require-dev": {
"symfony/phpunit-bridge": "^4.0 | ^5.0",
"symfony/framework-bundle": "^4.0 | ^5.0",
"jackalope/jackalope-doctrine-dbal": "^1.3.4",
"symfony/browser-kit": "^4.0 | ^5.0",
"jackalope/jackalope-doctrine-dbal": "^1.3.4"
"symfony/phpunit-bridge": "^4.0 | ^5.0",
"symfony/console": "^4.0 | ^5.0"
},
"autoload": {
"psr-4": {
Expand All @@ -37,5 +37,8 @@
"psr-4": {
"Manuxi\\SuluEventBundle\\Tests\\": "tests/"
}
},
"scripts": {

}
}
4 changes: 3 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="./vendor/autoload.php"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
<ini name="intl.default_locale" value="en" />
<ini name="intl.error_level" value="0" />
<ini name="memory_limit" value="-1" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0" />
<env name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="APP_ENV" value="test" force="true" />
</php>

<testsuites>
Expand Down
12 changes: 0 additions & 12 deletions src/Resources/config/routes.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
#<?xml version="1.0" encoding="UTF-8" ?>
#<routes xmlns="http://symfony.com/schema/routing"
# xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
# xsi:schemaLocation="http://symfony.com/schema/routing
# http://symfony.com/schema/routing/routing-1.0.xsd">
#
# <route id="event" controller="Manuxi\SuluEventBundle\Controller\Website\EventController::indexAction">
# <path locale="de">/veranstaltungen/{id}/{slug}</path>
# <path locale="en">/events/{id}/{slug}</path>
# </route>
#
#</routes>
event:
path:
en: /events/{id}/{slug}
Expand Down
29 changes: 29 additions & 0 deletions tests/App/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Manuxi\SuluEventBundle\Tests\App;

use Manuxi\SuluEventBundle\SuluEventBundle;
use Sulu\Bundle\TestBundle\Kernel\SuluTestKernel;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;

class Kernel extends SuluTestKernel
{
/**
* @return BundleInterface[]
*/
public function registerBundles(): array
{
/** @var BundleInterface[] $bundles */
$bundles = parent::registerBundles();
$bundles[] = new SuluEventBundle();

return $bundles;
}

public function getProjectDir(): string
{
return __DIR__;
}
}
76 changes: 76 additions & 0 deletions tests/Unit/Content/Type/EventSelectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

declare(strict_types=1);

namespace Manuxi\SuluEventBundle\Tests\Unit\Content\Type;

use Manuxi\SuluEventBundle\Content\Type\EventSelection;
use Manuxi\SuluEventBundle\Entity\Event;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectRepository;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Component\Content\Compat\PropertyInterface;

class EventSelectionTest extends TestCase
{
private $eventSelection;

/**
* @var ObjectProphecy<ObjectRepository<Event>>
*/
private $eventRepository;

protected function setUp(): void
{
$this->eventRepository = $this->prophesize(ObjectRepository::class);
$entityManager = $this->prophesize(EntityManagerInterface::class);
$entityManager->getRepository(Event::class)->willReturn($this->eventRepository->reveal());

$this->eventSelection = new EventSelection($entityManager->reveal());
}

public function testNullValue(): void
{
$property = $this->prophesize(PropertyInterface::class);
$property->getValue()->willReturn(null);

$this->assertSame([], $this->eventSelection->getContentData($property->reveal()));
$this->assertSame(['ids' => null], $this->eventSelection->getViewData($property->reveal()));
}

public function testEmptyArrayValue(): void
{
$property = $this->prophesize(PropertyInterface::class);
$property->getValue()->willReturn([]);

$this->assertSame([], $this->eventSelection->getContentData($property->reveal()));
$this->assertSame(['ids' => []], $this->eventSelection->getViewData($property->reveal()));
}

public function testValidValue(): void
{
$property = $this->prophesize(PropertyInterface::class);
$property->getValue()->willReturn([45, 22]);

$event22 = $this->prophesize(Event::class);
$event22->getId()->willReturn(22);

$event45 = $this->prophesize(Event::class);
$event45->getId()->willReturn(45);

$this->eventRepository->findBy(['id' => [45, 22]])->willReturn([
$event22->reveal(),
$event45->reveal(),
]);

$this->assertSame(
[
$event45->reveal(),
$event22->reveal(),
],
$this->eventSelection->getContentData($property->reveal())
);
$this->assertSame(['ids' => [45, 22]], $this->eventSelection->getViewData($property->reveal()));
}
}
54 changes: 54 additions & 0 deletions tests/Unit/Content/Type/SingleEventSelectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace Manuxi\SuluEventBundle\Tests\Unit\Content\Type;

use Manuxi\SuluEventBundle\Content\Type\SingleEventSelection;
use Manuxi\SuluEventBundle\Entity\Event;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectRepository;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Component\Content\Compat\PropertyInterface;

class SingleEventSelectionTest extends TestCase
{
private $singleEventSelection;

/**
* @var ObjectProphecy<ObjectRepository<Event>>
*/
private $eventRepository;

protected function setUp(): void
{
$this->eventRepository = $this->prophesize(ObjectRepository::class);
$entityManager = $this->prophesize(EntityManagerInterface::class);
$entityManager->getRepository(Event::class)->willReturn($this->eventRepository->reveal());

$this->singleEventSelection = new SingleEventSelection($entityManager->reveal());
}

public function testNullValue(): void
{
$property = $this->prophesize(PropertyInterface::class);
$property->getValue()->willReturn(null);

$this->assertNull($this->singleEventSelection->getContentData($property->reveal()));
$this->assertSame(['id' => null], $this->singleEventSelection->getViewData($property->reveal()));
}

public function testValidValue(): void
{
$property = $this->prophesize(PropertyInterface::class);
$property->getValue()->willReturn(45);

$event45 = $this->prophesize(Event::class);

$this->eventRepository->find(45)->willReturn($event45->reveal());

$this->assertSame($event45->reveal(), $this->singleEventSelection->getContentData($property->reveal()));
$this->assertSame(['id' => 45], $this->singleEventSelection->getViewData($property->reveal()));
}
}
Loading

0 comments on commit 39104b5

Please sign in to comment.