This repository has been archived by the owner on Feb 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
[WIP] common collaborators #3
Open
docteurklein
wants to merge
18
commits into
phpspec:master
Choose a base branch
from
docteurklein:feature/common-collaborators
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
55f260f
[WIP] add common collaborators maintainer
docteurklein 0f6d68f
refactor specs
docteurklein 634f37b
describe feature
docteurklein 64b7da5
refactor extension to allow params
docteurklein 11feb78
remove superseeded maintainers
docteurklein 05ebcd7
do not use extension config yet
docteurklein 36b9c28
fix typo
docteurklein 0e97ad4
fix scenario about common collaborators
docteurklein 35740e8
introduce collaborator initializers
docteurklein 1483774
add default initilaizers
docteurklein 43de656
fix postInitialize
docteurklein e40642c
improve doctrine init
docteurklein ae0deda
add examples
docteurklein c18f931
improve postInit
docteurklein ee29164
move id alias config
docteurklein 01363b0
use dynamic name
docteurklein 924fe12
fix service id of container
docteurklein 5c96a1f
activate templating initializer
docteurklein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,55 @@ | ||
Feature: Initialize default collaborators | ||
As a Developer | ||
I want default collaborators to be preconfigured | ||
In order to avoid complex let methods | ||
|
||
Background: | ||
Given the Symfony extension is enabled with: | ||
""" | ||
extensions: | ||
- PhpSpec\Symfony2Extension\Extension | ||
|
||
symfony2_extension.common-collaborators: | ||
container: { service_container: ~ } | ||
router: ~ | ||
templating: ~ | ||
request: ~ | ||
session: ~ | ||
doctrine: ~ | ||
""" | ||
|
||
Scenario: Controller spec has access to common collaborators | ||
Given I wrote a spec in the "src/Scenario8/Bundle/DemoBundle/Spec/Controller/UserControllerSpec.php": | ||
""" | ||
<?php | ||
|
||
namespace Scenario8\Bundle\DemoBundle\Spec\Controller; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
|
||
class UserControllerSpec extends ObjectBehavior | ||
{ | ||
function its_generateUrl_generates_urls($container) | ||
{ | ||
$this->setContainer($container); | ||
$this->generateUrl('homepage')->shouldReturn('homepage'); // preconfigured router! | ||
} | ||
} | ||
|
||
""" | ||
And I wrote a class in the "src/Scenario8/Bundle/DemoBundle/Controller/UserController.php": | ||
""" | ||
<?php | ||
|
||
namespace Scenario8\Bundle\DemoBundle\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
|
||
class UserController extends Controller | ||
{ | ||
} | ||
|
||
""" | ||
When I run phpspec | ||
Then I should see "1 example (1 passed)" |
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,51 @@ | ||
Feature: Provide default collaborators | ||
As a Developer | ||
I want to avoid configuring framework mocks every time by hand | ||
In order to have a working preconfigured set of mocks | ||
|
||
Background: | ||
Given the Symfony extension is enabled with: | ||
""" | ||
extensions: | ||
- PhpSpec\Symfony2Extension\Extension | ||
|
||
symfony2_extension.common-collaborators: | ||
container: { service_container: ~ } | ||
router: Symfony\Component\Routing\RouterInterface | ||
""" | ||
|
||
Scenario: Controller spec has access to common collaborators | ||
Given I wrote a spec in the "src/Scenario7/Bundle/DemoBundle/Spec/Controller/UserControllerSpec.php": | ||
""" | ||
<?php | ||
|
||
namespace Scenario7\Bundle\DemoBundle\Spec\Controller; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
|
||
class UserControllerSpec extends ObjectBehavior | ||
{ | ||
function its_generateUrl_generates_urls($container) | ||
{ | ||
$this->setContainer($container); | ||
$this->generateUrl('homepage')->shouldReturn('homepage'); | ||
} | ||
} | ||
|
||
""" | ||
And I wrote a class in the "src/Scenario7/Bundle/DemoBundle/Controller/UserController.php": | ||
""" | ||
<?php | ||
|
||
namespace Scenario7\Bundle\DemoBundle\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
|
||
class UserController extends Controller | ||
{ | ||
} | ||
|
||
""" | ||
When I run phpspec | ||
Then I should see "1 example (1 passed)" |
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,14 @@ | ||
extensions: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for the example. (to be removed) |
||
- PhpSpec\Symfony2Extension\Extension | ||
|
||
symfony2_extension.common-collaborators: | ||
# append: false # should we support append ? (ie: provide defaults) | ||
container: { service_container: ~ } | ||
router: ~ | ||
templating: ~ | ||
request: ~ | ||
session: ~ | ||
doctrine: ~ | ||
em: ~ | ||
repository: ~ | ||
#formFactory: { form.factory: FormFactoryInterface } |
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
27 changes: 27 additions & 0 deletions
27
spec/PhpSpec/Symfony2Extension/Runner/Collaborator/DefaultFactorySpec.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,27 @@ | ||
<?php | ||
|
||
namespace spec\PhpSpec\Symfony2Extension\Runner\Collaborator; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
use PhpSpec\Wrapper\Unwrapper; | ||
use Prophecy\Prophecy\ObjectProphecy; | ||
use PhpSpec\Runner\CollaboratorManager; | ||
|
||
class DefaultFactorySpec extends ObjectBehavior | ||
{ | ||
function let(Unwrapper $unwrapper) | ||
{ | ||
$this->beConstructedWith($unwrapper); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('PhpSpec\Symfony2Extension\Runner\Collaborator\DefaultFactory'); | ||
} | ||
|
||
function its_create_should_create_collaborators(CollaboratorManager $collaborators, ObjectProphecy $prophecy) | ||
{ | ||
$this->create($collaborators, $prophecy, 'router', 'Symfony\Component\Routing\RouterInterface')->shouldHaveType('PhpSpec\Wrapper\Collaborator'); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
spec/PhpSpec/Symfony2Extension/Runner/Collaborator/InitializerFactorySpec.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,38 @@ | ||
<?php | ||
|
||
namespace spec\PhpSpec\Symfony2Extension\Runner\Collaborator; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
use PhpSpec\Symfony2Extension\Runner\Collaborator\FactoryInterface; | ||
use Prophecy\Prophecy\ObjectProphecy; | ||
use PhpSpec\Symfony2Extension\Runner\Collaborator\InitializerInterface; | ||
use PhpSpec\Wrapper\Collaborator; | ||
use PhpSpec\Runner\CollaboratorManager; | ||
|
||
class InitializerFactorySpec extends ObjectBehavior | ||
{ | ||
private $closure; | ||
|
||
function let(FactoryInterface $factory, Collaborator $collaborator, InitializerInterface $initializer) | ||
{ | ||
$this->beConstructedWith($factory, array( | ||
$initializer, | ||
)); | ||
$factory->create(Argument::cetera())->willReturn($collaborator); | ||
} | ||
|
||
function its_create_should_initialize_known_collaborators(CollaboratorManager $collaborators, ObjectProphecy $prophecy, $collaborator, $initializer) | ||
{ | ||
$initializer->supports('router')->willReturn(true); | ||
$initializer->initialize(Argument::cetera())->shouldBeCalled(); | ||
$this->create($collaborators, $prophecy, 'router'); | ||
} | ||
|
||
function its_create_should_not_initialize_unknown_collaborators(CollaboratorManager $collaborators, ObjectProphecy $prophecy, $collaborator, $initializer) | ||
{ | ||
$initializer->supports('request')->willReturn(false); | ||
$initializer->initialize(Argument::cetera())->shouldNotBeCalled(); | ||
$this->create($collaborators, $prophecy, 'request'); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
spec/PhpSpec/Symfony2Extension/Runner/Maintainer/CommonCollaboratorsMaintainerSpec.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,21 @@ | ||
<?php | ||
|
||
namespace spec\PhpSpec\Symfony2Extension\Runner\Maintainer; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
use PhpSpec\Wrapper\Unwrapper; | ||
use PhpSpec\Symfony2Extension\Runner\Collaborator\InitializerFactory; | ||
|
||
class CommonCollaboratorsMaintainerSpec extends ObjectBehavior | ||
{ | ||
public function let(Unwrapper $unwrapper, InitializerFactory $factory) | ||
{ | ||
$this->beConstructedWith($unwrapper, $factory, array()); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('PhpSpec\Symfony2Extension\Runner\Maintainer\CommonCollaboratorsMaintainer'); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐴
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what with that ? 🐫
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👶 maybe he means the @ handling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah :) it's acceptable in that case imho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
si un médecin le dit, nous buvons 👶
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha :) don't trust me.