浏览代码

add phpspec/prophecy-phpunit to replace deprecated prohesize method

Olivier Massot 1 年之前
父节点
当前提交
4d3b8959f4

+ 2 - 0
.gitignore

@@ -4,3 +4,5 @@
 composer.lock
 coverage/
 *.log
+
+ot_core/composer.phar

+ 2 - 1
composer.json

@@ -76,6 +76,7 @@
         }
     },
     "require-dev": {
-        "ssch/typo3-rector": "^1.3"
+        "ssch/typo3-rector": "^1.3",
+        "phpspec/prophecy": "^1.19"
     }
 }

文件差异内容过多而无法显示
+ 0 - 0
ot_core/Tests/Build/.phpunit.result.cache


+ 6 - 2
ot_core/Tests/Unit/Controller/SelectedSiteControllerTest.php

@@ -9,12 +9,14 @@ use Opentalent\OtCore\Exception\NoSuchWebsiteException;
 use Opentalent\OtCore\Website\OtPageRepository;
 use Opentalent\OtCore\Website\OtWebsiteRepository;
 use Prophecy\Argument;
+use TYPO3\CMS\Extbase\Mvc\RequestInterface;
 
 class SelectedSiteControllerTest extends UnitTestCase
 {
     private $controller;
 
-    public function setUp() {
+    public function setUp(): void
+    {
         $this->controller = new SelectedSiteController();
     }
 
@@ -40,11 +42,13 @@ class SelectedSiteControllerTest extends UnitTestCase
         $method = $reflection->getMethod('callActionMethod');
         $method->setAccessible(true);
 
+        $request = $this->getMockBuilder(RequestInterface::class)->disableOriginalConstructor()->getMock();
+
         $argumentsProperty = $reflection->getProperty('preventPropagation');
         $argumentsProperty->setAccessible(true);;
         $argumentsProperty->setValue($this->controller, true);
 
-        $method->invokeArgs($this->controller, []);
+        $method->invokeArgs($this->controller, [$request]);
 
         $currentRootUidProperty = $reflection->getProperty('currentRootUid');
         $currentRootUidProperty->setAccessible(true);

+ 2 - 1
ot_core/Tests/Unit/Domain/Repository/AbstractApiRepositoryTestCase.php

@@ -36,7 +36,8 @@ abstract class AbstractApiRepositoryTestCase extends UnitTestCase
 
     protected $service;
 
-    public function setUp() {
+    public function setUp(): void
+    {
         // mock the application context
         $this->context = $this->prophesize(ApplicationContext::class);
         $this->context->isProduction()->willReturn(false);

+ 3 - 2
ot_core/Tests/Unit/Domain/Repository/BaseApiRepositoryTest.php

@@ -2,10 +2,9 @@
 
 namespace Opentalent\OtCore\Tests\Unit\Domain\Repository;
 
-use GuzzleHttp\Client;
 use Opentalent\OtCore\Domain\Repository\ApiPagedCollection;
 use Opentalent\OtCore\Domain\Repository\BaseApiRepository;
-use Opentalent\OtCore\Exception\ApiRequestException;
+use Prophecy\PhpUnit\ProphecyTrait;
 
 /**
  * Proxy to reveal the private methods of the abstract class BaseApiRepository
@@ -19,6 +18,8 @@ class ConcreteBaseApiRepository extends BaseApiRepository {
 
 class BaseApiRepositoryTest extends AbstractApiRepositoryTestCase
 {
+    use ProphecyTrait;
+
     const TESTED_CLASS = 'Opentalent\OtCore\Tests\Unit\Domain\Repository\ConcreteBaseApiRepository';
 
     /**

+ 3 - 1
ot_core/Tests/Unit/Domain/Repository/DonorRepositoryTest.php

@@ -2,11 +2,13 @@
 
 namespace Opentalent\OtCore\Tests\Unit\Domain\Repository;
 
-use Opentalent\OtCore\Domain\Repository\DonorRepository;
+use Prophecy\PhpUnit\ProphecyTrait;
 
 
 class DonorRepositoryTest extends AbstractApiRepositoryTestCase
 {
+    use ProphecyTrait;
+
     const TESTED_CLASS = "Opentalent\OtCore\Domain\Repository\DonorRepository";
 
     /**

+ 3 - 1
ot_core/Tests/Unit/Domain/Repository/EventRepositoryTest.php

@@ -2,11 +2,13 @@
 
 namespace Opentalent\OtCore\Tests\Unit\Domain\Repository;
 
-use Opentalent\OtCore\Domain\Repository\EventRepository;
+use Prophecy\PhpUnit\ProphecyTrait;
 
 
 class EventRepositoryTest extends AbstractApiRepositoryTestCase
 {
+    use ProphecyTrait;
+
     const TESTED_CLASS = "Opentalent\OtCore\Domain\Repository\EventRepository";
 
     /**

+ 3 - 1
ot_core/Tests/Unit/Domain/Repository/MemberRepositoryTest.php

@@ -2,11 +2,13 @@
 
 namespace Opentalent\OtCore\Tests\Unit\Domain\Repository;
 
-use Opentalent\OtCore\Domain\Repository\MemberRepository;
+use Prophecy\PhpUnit\ProphecyTrait;
 
 
 class MemberRepositoryTest extends AbstractApiRepositoryTestCase
 {
+    use ProphecyTrait;
+
     const TESTED_CLASS = "Opentalent\OtCore\Domain\Repository\MemberRepository";
 
     /**

+ 3 - 0
ot_core/Tests/Unit/Domain/Repository/OrganizationRepositoryTest.php

@@ -3,10 +3,13 @@
 namespace Opentalent\OtCore\Tests\Unit\Domain\Repository;
 
 use Opentalent\OtCore\Domain\Repository\OrganizationRepository;
+use Prophecy\PhpUnit\ProphecyTrait;
 
 
 class OrganizationRepositoryTest extends AbstractApiRepositoryTestCase
 {
+    use ProphecyTrait;
+
     const TESTED_CLASS = "Opentalent\OtCore\Domain\Repository\OrganizationRepository";
 
     /**

+ 5 - 1
ot_core/Tests/Unit/Service/OpentalentApiServiceTest.php

@@ -10,10 +10,13 @@ use Opentalent\OtCore\Service\OpentalentApiService;
 use Opentalent\OtCore\Tests\Unit\Fixtures\ApiResponseFixtures;
 use PHPUnit\TextUI\RuntimeException;
 use Prophecy\Argument;
+use Prophecy\PhpUnit\ProphecyTrait;
 use TYPO3\CMS\Core\Core\ApplicationContext;
 
 class OpentalentApiServiceTest extends UnitTestCase
 {
+    use ProphecyTrait;
+
     protected $context;
     /**
      * @var ApiResponseFixtures
@@ -26,7 +29,8 @@ class OpentalentApiServiceTest extends UnitTestCase
 
     protected $service;
 
-    public function setUp() {
+    public function setUp(): void
+    {
         // mock the application context
         $this->context = $this->prophesize(ApplicationContext::class);
         $this->context->isProduction()->willReturn(false);

+ 5 - 1
ot_core/Tests/Unit/Website/OtPageRepositoryTest.php

@@ -7,19 +7,23 @@ use Opentalent\OtCore\Website\OtPageRepository;
 use Nimut\TestingFramework\TestCase\UnitTestCase;
 use Opentalent\OtCore\Tests\Unit\Fixtures\PageFixtures;
 use Opentalent\OtCore\Tests\Unit\QueryBuilderProphet;
+use Prophecy\PhpUnit\ProphecyTrait;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Domain\Repository\PageRepository;
 
 
 class OtPageRepositoryTest extends UnitTestCase
 {
+    use ProphecyTrait;
+
     protected $pageService;
     protected $pageRepository;
     protected $connectionPool;
     protected $pageFixtures;
     protected $otPageRepository;
 
-    public function setUp() {
+    public function setUp(): void
+    {
         // Prophecies to be injected in the under test OtPageRepository
         $this->pageService = $this->prophesize(PageService::class);
         $this->pageRepository = $this->prophesize(PageRepository::class);

+ 5 - 1
ot_core/Tests/Unit/Website/OtWebsiteRepositoryTest.php

@@ -12,16 +12,20 @@ use Opentalent\OtCore\Tests\Unit\Fixtures\WebsiteFixtures;
 use Opentalent\OtCore\Tests\Unit\QueryBuilderProphet;
 use Opentalent\OtCore\Website\OtPageRepository;
 use Opentalent\OtCore\Website\OtWebsiteRepository;
+use Prophecy\PhpUnit\ProphecyTrait;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 
 class OtWebsiteRepositoryTest extends UnitTestCase
 {
+    use ProphecyTrait;
+
     protected $connectionPool;
     protected $pageFixtures;
     protected $websiteFixtures;
     protected $otWebsiteRepository;
 
-    public function setUp() {
+    public function setUp(): void
+    {
         // Prophecies to be injected in the under test OtPageRepository
         $this->connectionPool = $this->prophesize(ConnectionPool::class);
 

+ 3 - 2
ot_core/composer.json

@@ -46,8 +46,6 @@
             "Opentalent\\OtCore\\Tests\\": "Tests"
         }
     },
-    "require-dev": {
-    },
     "scripts": {
         "post-autoload-dump": [
             "@prepare-extension-test-structure"
@@ -62,5 +60,8 @@
             "web-dir": ".Build/Web",
             "extension-key": "ot_core"
         }
+    },
+    "require-dev": {
+        "phpspec/prophecy-phpunit": "^2.2"
     }
 }

部分文件因为文件数量过多而无法显示