Skip to content

Commit

Permalink
Update use ProphecyTrait usage
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Jul 24, 2024
1 parent 2ec0fc1 commit 0058ea2
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 22 deletions.
3 changes: 3 additions & 0 deletions Tests/Unit/Controller/RedirectControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
namespace Sulu\Bundle\RedirectBundle\Tests\Unit\Controller;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Sulu\Bundle\RedirectBundle\Controller\WebsiteRedirectController;
use Sulu\Bundle\RedirectBundle\Model\RedirectRouteInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;

class RedirectControllerTest extends TestCase
{
use ProphecyTrait;

/**
* @var WebsiteRedirectController
*/
Expand Down
35 changes: 14 additions & 21 deletions Tests/Unit/Controller/RedirectRouteImportControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Sulu\Bundle\RedirectBundle\Controller\RedirectRouteImportController;
use Sulu\Bundle\RedirectBundle\Import\Converter\ConverterNotFoundException;
use Sulu\Bundle\RedirectBundle\Import\FileImportInterface;
Expand All @@ -27,6 +28,8 @@

class RedirectRouteImportControllerTest extends TestCase
{
use ProphecyTrait;

/**
* @var string
*/
Expand All @@ -39,15 +42,12 @@ class RedirectRouteImportControllerTest extends TestCase

public function testImportAction()
{
$request = $this->prophesize(Request::class);

$fileBag = $this->prophesize(FileBag::class);
$request->reveal()->files = $fileBag->reveal();
$request = Request::create('/');

$uploadedFile = $this->createUploadedFile(__DIR__ . '/import.csv');

$fileBag->has('redirectRoutes')->willReturn(true);
$fileBag->get('redirectRoutes')->willReturn($uploadedFile);
$request->files->add([
'redirectRoutes' => $uploadedFile,
]);

$items = [
new Item(1, '', $this->prophesize(RedirectRouteInterface::class)->reveal()),

Check failure on line 53 in Tests/Unit/Controller/RedirectRouteImportControllerTest.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Call to an undefined method Sulu\Bundle\RedirectBundle\Tests\Unit\Controller\RedirectRouteImportControllerTest::prophesize().
Expand All @@ -59,7 +59,7 @@ public function testImportAction()
$import->import(Argument::any())->willReturn($items);

$controller = new RedirectRouteImportController($import->reveal(), $this->importPath);
$response = $controller->postAction($request->reveal());
$response = $controller->postAction($request);

$this->assertInstanceOf(JsonResponse::class, $response);
$this->assertEquals(200, $response->getStatusCode());
Expand Down Expand Up @@ -96,15 +96,12 @@ public function testImportActionReaderNotFound()

public function testImportActionConverterNotFound()
{
$request = $this->prophesize(Request::class);

$fileBag = $this->prophesize(FileBag::class);
$request->reveal()->files = $fileBag->reveal();
$request = Request::create('/');

$uploadedFile = $this->createUploadedFile(__DIR__ . '/import.csv');

$fileBag->has('redirectRoutes')->willReturn(true);
$fileBag->get('redirectRoutes')->willReturn($uploadedFile);
$request->files->add([
'redirectRoutes' => $uploadedFile,
]);

$import = $this->prophesize(FileImportInterface::class);

Check failure on line 106 in Tests/Unit/Controller/RedirectRouteImportControllerTest.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Call to an undefined method Sulu\Bundle\RedirectBundle\Tests\Unit\Controller\RedirectRouteImportControllerTest::prophesize().
$import->import(Argument::any())->willThrow(ConverterNotFoundException::class);
Expand All @@ -118,12 +115,8 @@ public function testImportActionConverterNotFound()

public function testImportActionNoFile()
{
$request = $this->prophesize(Request::class);

$fileBag = $this->prophesize(FileBag::class);
$request->reveal()->files = $fileBag->reveal();

$fileBag->has('redirectRoutes')->willReturn(false);
$request = Request::create('/');
$request->files->add([]);

$import = $this->prophesize(FileImportInterface::class);
$import->import(Argument::any())->shouldNotBeCalled();
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/GoneSubscriber/GoneDocumentSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Doctrine\ORM\EntityManager;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Bundle\DocumentManagerBundle\Bridge\DocumentInspector;
use Sulu\Bundle\PageBundle\Document\BasePageDocument;
Expand All @@ -30,6 +31,8 @@

class GoneDocumentSubscriberTest extends TestCase
{
use ProphecyTrait;

/**
* @var GoneDocumentSubscriber
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/GoneSubscriber/GoneEntitySubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Doctrine\ORM\Event\LifecycleEventArgs;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Bundle\RedirectBundle\Entity\RedirectRoute;
use Sulu\Bundle\RedirectBundle\GoneSubscriber\GoneEntitySubscriber;
Expand All @@ -22,6 +23,8 @@

class GoneEntitySubscriberTest extends TestCase
{
use ProphecyTrait;

/**
* @var GoneEntitySubscriber
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Import/Converter/ConverterFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
namespace Sulu\Bundle\RedirectBundle\Tests\Unit\Import\Converter;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Bundle\RedirectBundle\Import\Converter\ConverterFacade;
use Sulu\Bundle\RedirectBundle\Import\Converter\ConverterInterface;
use Sulu\Bundle\RedirectBundle\Model\RedirectRouteInterface;

class ConverterFacadeTest extends TestCase
{
use ProphecyTrait;

public function testSupports()
{
$data = ['title' => 'Test-Title'];
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Import/Converter/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@

use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Sulu\Bundle\RedirectBundle\Import\Converter\Converter;
use Sulu\Bundle\RedirectBundle\Model\RedirectRouteInterface;
use Sulu\Bundle\RedirectBundle\Model\RedirectRouteRepositoryInterface;

class ConverterTest extends TestCase
{
use ProphecyTrait;

public function testSupports()
{
$repository = $this->prophesize(RedirectRouteRepositoryInterface::class);
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Import/FileImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Bundle\RedirectBundle\Import\Converter\Converter;
use Sulu\Bundle\RedirectBundle\Import\Converter\ConverterInterface;
Expand All @@ -28,6 +29,8 @@

class FileImportTest extends TestCase
{
use ProphecyTrait;

/**
* @var ObjectProphecy<ReaderInterface>
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Import/Reader/ReaderFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
namespace Sulu\Bundle\RedirectBundle\Tests\Unit\Import\Reader;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Bundle\RedirectBundle\Import\Converter\Converter;
use Sulu\Bundle\RedirectBundle\Import\Reader\ReaderFacade;
use Sulu\Bundle\RedirectBundle\Import\Reader\ReaderInterface;

class ReaderFacadeTest extends TestCase
{
use ProphecyTrait;

/**
* @var string
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Import/Writer/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Bundle\RedirectBundle\Exception\RedirectRouteNotUniqueException;
use Sulu\Bundle\RedirectBundle\Import\Writer\DuplicatedSourceException;
Expand All @@ -24,6 +25,8 @@

class WriterTest extends TestCase
{
use ProphecyTrait;

/**
* @var ObjectProphecy<RedirectRouteManagerInterface>
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Manager/RedirectRouteManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Bundle\RedirectBundle\Exception\RedirectRouteNotUniqueException;
use Sulu\Bundle\RedirectBundle\Manager\RedirectRouteManager;
Expand All @@ -22,6 +23,8 @@

class RedirectRouteManagerTest extends TestCase
{
use ProphecyTrait;

/**
* @var ObjectProphecy<RedirectRouteRepositoryInterface>
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/Routing/RedirectRouteProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Sulu\Bundle\RedirectBundle\Tests\Unit\Routing;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Sulu\Bundle\RedirectBundle\Model\RedirectRouteInterface;
use Sulu\Bundle\RedirectBundle\Model\RedirectRouteRepositoryInterface;
use Sulu\Bundle\RedirectBundle\Routing\RedirectRouteProvider;
Expand All @@ -20,6 +21,8 @@

class RedirectRouteProviderTest extends TestCase
{
use ProphecyTrait;

/**
* @var RedirectRouteRepositoryInterface
*/
Expand Down
19 changes: 19 additions & 0 deletions Tests/prophecy-trailt-bc-layer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* 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 Prophecy\PhpUnit;

/**
* @internal
*/
trait ProphecyTrait
{
}
4 changes: 4 additions & 0 deletions Tests/test-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
*/

require __DIR__ . '/Application/config/bootstrap.php';

if (!\trait_exists(Prophecy\PhpUnit\ProphecyTrait::class)) { // backwards compatibility layer for < PHP 7.3
require __DIR__ . '/prophecy-trait-bc-layer.php';
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"jackalope/jackalope-doctrine-dbal": "^1.3.4 || ^2.0",
"handcraftedinthealps/zendsearch": "^2.0",
"symfony/framework-bundle": "^4.3 || ^5.0 || ^6.0 || ^7.0",
"phpspec/prophecy": "^1.10"
"phpspec/prophecy": "^1.10",
"phpspec/prophecy-phpunit": "^1.0 || ^2.0"
},
"keywords": [
"redirects"
Expand Down

0 comments on commit 0058ea2

Please sign in to comment.