-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
211 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Resource\Tests\Context; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Sylius\Component\Resource\Tests\Dummy\DummyClassOne; | ||
use Sylius\Component\Resource\Tests\Dummy\DummyClassTwo; | ||
use Sylius\Resource\Context\Context; | ||
|
||
final class ContextTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_is_an_iterator(): void | ||
{ | ||
$context = new Context(); | ||
$this->assertInstanceOf(\IteratorAggregate::class, $context); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_be_constructed_with_options(): void | ||
{ | ||
$optionOne = new DummyClassOne(); | ||
$optionTwo = new DummyClassTwo(); | ||
|
||
$context = new Context($optionOne, $optionTwo); | ||
|
||
$this->assertEquals($optionOne, $context->get(DummyClassOne::class)); | ||
$this->assertEquals($optionTwo, $context->get(DummyClassTwo::class)); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_be_with_options(): void | ||
{ | ||
$optionOne = new DummyClassOne(); | ||
$optionTwo = new DummyClassTwo(); | ||
|
||
$context = new Context(); | ||
$context = $context->with($optionOne, $optionTwo); | ||
|
||
$this->assertEquals($optionOne, $context->get(DummyClassOne::class)); | ||
$this->assertEquals($optionTwo, $context->get(DummyClassTwo::class)); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_be_without_options(): void | ||
{ | ||
$optionOne = new DummyClassOne(); | ||
$optionTwo = new DummyClassTwo(); | ||
|
||
$context = new Context(); | ||
$context = $context->with($optionOne, $optionTwo); | ||
$context = $context->without(DummyClassOne::class, DummyClassTwo::class); | ||
|
||
$this->assertNull($context->get(DummyClassOne::class)); | ||
$this->assertNull($context->get(DummyClassTwo::class)); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_be_iterated(): void | ||
{ | ||
$optionOne = new DummyClassOne(); | ||
$optionTwo = new DummyClassTwo(); | ||
|
||
$context = new Context($optionOne, $optionTwo); | ||
|
||
$this->assertEquals($optionOne, $context->getIterator()->current()); | ||
$this->assertEquals(2, iterator_count($context->getIterator())); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/Component/tests/Context/Initiator/RequestContextInitiatorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Resource\Tests\Context\Initiator; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
use Sylius\Resource\Context\Context; | ||
use Sylius\Resource\Context\Initiator\RequestContextInitiator; | ||
use Sylius\Resource\Context\Option\RequestOption; | ||
use Symfony\Component\HttpFoundation\ParameterBag; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
final class RequestContextInitiatorTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
private RequestContextInitiator $requestContextInitiator; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->requestContextInitiator = new RequestContextInitiator(); | ||
} | ||
|
||
/** @test */ | ||
public function it_initializes_context(): void | ||
{ | ||
$request = $this->prophesize(Request::class); | ||
|
||
$request->attributes = new ParameterBag(['_sylius' => ['resource_class' => 'App\Resource']]); | ||
|
||
$context = $this->requestContextInitiator->initializeContext($request->reveal()); | ||
|
||
$this->assertInstanceOf(Context::class, $context); | ||
$this->assertEquals($request->reveal(), $context->get(RequestOption::class)?->request()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Resource\Tests\Context\Option; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
use Prophecy\Prophecy\ObjectProphecy; | ||
use Sylius\Resource\Metadata\MetadataInterface; | ||
use Sylius\Resource\Context\Option\MetadataOption; | ||
|
||
final class MetadataOptionTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
private MetadataInterface|ObjectProphecy $metadata; | ||
|
||
private MetadataOption $metadataOption; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->metadata = $this->prophesize(MetadataInterface::class); | ||
|
||
$this->metadataOption = new MetadataOption($this->metadata->reveal()); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_request_configuration(): void | ||
{ | ||
$this->assertEquals($this->metadata->reveal(), $this->metadataOption->metadata()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Resource\Tests\Context\Option; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
use Prophecy\Prophecy\ObjectProphecy; | ||
use Sylius\Resource\Context\Option\RequestOption; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
final class RequestOptionTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
private Request|ObjectProphecy $request; | ||
|
||
private RequestOption $requestOption; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->request = $this->prophesize(Request::class); | ||
|
||
$this->requestOption = new RequestOption($this->request->reveal()); | ||
} | ||
|
||
/** @test */ | ||
public function it_contains_request(): void | ||
{ | ||
$this->assertEquals($this->request->reveal(), $this->requestOption->request()); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
src/Component/tests/spec/Context/Initiator/RequestContextInitiatorSpec.php
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
src/Component/tests/spec/Context/Option/RequestOptionSpec.php
This file was deleted.
Oops, something went wrong.