Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cover specs with PHPStan #10059

Merged
merged 6 commits into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"zendframework/zend-stdlib": "^3.1"
},
"require-dev": {
"akeneo/phpspec-skip-example-extension": "^3.0",
"akeneo/phpspec-skip-example-extension": "^4.0",
"behat/behat": "^3.2",
"behat/mink": "^1.7@dev",
"behat/mink-browserkit-driver": "^1.3",
Expand All @@ -90,7 +90,7 @@
"matthiasnoback/symfony-dependency-injection-test": "^2.0",
"mikey179/vfsStream": "^1.6",
"pamil/prophecy-common": "^0.1",
"phpspec/phpspec": "^4.0",
"phpspec/phpspec": "^5.0",
"phpstan/phpstan-doctrine": "^0.10",
"phpstan/phpstan-shim": "^0.10",
"phpstan/phpstan-symfony": "^0.10",
Expand Down Expand Up @@ -190,7 +190,57 @@
},
"autoload-dev": {
"psr-4": {
"Sylius\\Tests\\": "tests/"
"Sylius\\Tests\\": "tests/",
"spec\\Sylius\\Behat\\": "src/Sylius/Behat/spec/",
"spec\\Sylius\\Component\\Addressing\\": "src/Sylius/Component/Addressing/spec/",
"spec\\Sylius\\Component\\Attribute\\": "src/Sylius/Component/Attribute/spec/",
"spec\\Sylius\\Component\\Channel\\": "src/Sylius/Component/Channel/spec/",
"spec\\Sylius\\Component\\Core\\": "src/Sylius/Component/Core/spec/",
"spec\\Sylius\\Component\\Currency\\": "src/Sylius/Component/Currency/spec/",
"spec\\Sylius\\Component\\Customer\\": "src/Sylius/Component/Customer/spec/",
"spec\\Sylius\\Component\\Grid\\": "src/Sylius/Component/Grid/spec/",
"spec\\Sylius\\Component\\Inventory\\": "src/Sylius/Component/Inventory/spec/",
"spec\\Sylius\\Component\\Locale\\": "src/Sylius/Component/Locale/spec/",
"spec\\Sylius\\Component\\Mailer\\": "src/Sylius/Component/Mailer/spec/",
"spec\\Sylius\\Component\\Order\\": "src/Sylius/Component/Order/spec/",
"spec\\Sylius\\Component\\Payment\\": "src/Sylius/Component/Payment/spec/",
"spec\\Sylius\\Component\\Product\\": "src/Sylius/Component/Product/spec/",
"spec\\Sylius\\Component\\Promotion\\": "src/Sylius/Component/Promotion/spec/",
"spec\\Sylius\\Component\\Registry\\": "src/Sylius/Component/Registry/spec/",
"spec\\Sylius\\Component\\Resource\\": "src/Sylius/Component/Resource/spec/",
"spec\\Sylius\\Component\\Review\\": "src/Sylius/Component/Review/spec/",
"spec\\Sylius\\Component\\Shipping\\": "src/Sylius/Component/Shipping/spec/",
"spec\\Sylius\\Component\\Taxation\\": "src/Sylius/Component/Taxation/spec/",
"spec\\Sylius\\Component\\Taxonomy\\": "src/Sylius/Component/Taxonomy/spec/",
"spec\\Sylius\\Component\\User\\": "src/Sylius/Component/User/spec/",
"spec\\Sylius\\Bundle\\AddressingBundle\\": "src/Sylius/Bundle/AddressingBundle/spec/",
"spec\\Sylius\\Bundle\\AdminApiBundle\\": "src/Sylius/Bundle/AdminApiBundle/spec/",
"spec\\Sylius\\Bundle\\AdminBundle\\": "src/Sylius/Bundle/AdminBundle/spec/",
"spec\\Sylius\\Bundle\\AttributeBundle\\": "src/Sylius/Bundle/AttributeBundle/spec/",
"spec\\Sylius\\Bundle\\ChannelBundle\\": "src/Sylius/Bundle/ChannelBundle/spec/",
"spec\\Sylius\\Bundle\\CoreBundle\\": "src/Sylius/Bundle/CoreBundle/spec/",
"spec\\Sylius\\Bundle\\CurrencyBundle\\": "src/Sylius/Bundle/CurrencyBundle/spec/",
"spec\\Sylius\\Bundle\\CustomerBundle\\": "src/Sylius/Bundle/CustomerBundle/spec/",
"spec\\Sylius\\Bundle\\FixturesBundle\\": "src/Sylius/Bundle/FixturesBundle/spec/",
"spec\\Sylius\\Bundle\\GridBundle\\": "src/Sylius/Bundle/GridBundle/spec/",
"spec\\Sylius\\Bundle\\InventoryBundle\\": "src/Sylius/Bundle/InventoryBundle/spec/",
"spec\\Sylius\\Bundle\\LocaleBundle\\": "src/Sylius/Bundle/LocaleBundle/spec/",
"spec\\Sylius\\Bundle\\MailerBundle\\": "src/Sylius/Bundle/MailerBundle/spec/",
"spec\\Sylius\\Bundle\\MoneyBundle\\": "src/Sylius/Bundle/MoneyBundle/spec/",
"spec\\Sylius\\Bundle\\OrderBundle\\": "src/Sylius/Bundle/OrderBundle/spec/",
"spec\\Sylius\\Bundle\\PaymentBundle\\": "src/Sylius/Bundle/PaymentBundle/spec/",
"spec\\Sylius\\Bundle\\PayumBundle\\": "src/Sylius/Bundle/PayumBundle/spec/",
"spec\\Sylius\\Bundle\\ProductBundle\\": "src/Sylius/Bundle/ProductBundle/spec/",
"spec\\Sylius\\Bundle\\PromotionBundle\\": "src/Sylius/Bundle/PromotionBundle/spec/",
"spec\\Sylius\\Bundle\\ResourceBundle\\": "src/Sylius/Bundle/ResourceBundle/spec/",
"spec\\Sylius\\Bundle\\ReviewBundle\\": "src/Sylius/Bundle/ReviewBundle/spec/",
"spec\\Sylius\\Bundle\\ShippingBundle\\": "src/Sylius/Bundle/ShippingBundle",
"spec\\Sylius\\Bundle\\ShopBundle\\": "src/Sylius/Bundle/ShopBundle/spec/",
"spec\\Sylius\\Bundle\\TaxationBundle\\": "src/Sylius/Bundle/TaxationBundle/spec/",
"spec\\Sylius\\Bundle\\TaxonomyBundle\\": "src/Sylius/Bundle/TaxonomyBundle/spec/",
"spec\\Sylius\\Bundle\\ThemeBundle\\": "src/Sylius/Bundle/ThemeBundle/spec/",
"spec\\Sylius\\Bundle\\UiBundle\\": "src/Sylius/Bundle/UiBundle/spec/",
"spec\\Sylius\\Bundle\\UserBundle\\": "src/Sylius/Bundle/UserBundle/spec/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These repeated autoloads can be very hard to maintain and keep completed.

For monorepo and autoload-dev, the post autoload script might be sustainable solution: deprecated-packages/symplify@4d9ed30

Copy link
Contributor Author

@pamil pamil Jan 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like a pretty nice idea, but I think I prefer explicit configuration within composer.json to implicit one done by some PHP code which almost no one expects. Our list of components and bundles is quite stable, so maintenance won't be an issue here. Thanks for the heads up! :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure :)
Since it's monorepo and this removes the maintenance completely, I see the values in clear composer.json overrulling the lost explicitnes.

I got some feedback that monorepo autoloads are pretty WTF, compared to single psr-4 lines.

},
"classmap": ["app/AppKernel.php", "app/AppCache.php", "app/TestAppKernel.php"]
},
Expand Down
8 changes: 6 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ parameters:
reportUnmatchedIgnoredErrors: false

symfony:
container_xml_path: var/cache/dev/appDevDebugProjectContainer.xml
container_xml_path: var/cache/dev/appAppKernelDevDebugContainer.xml

excludes_analyse:
# Makes PHPStan crash
- '**/DependencyInjection/Configuration.php'

# Test dependencies
- '**/spec/**.php'
- '**/Bundle/*/test/app/**.php'
- '**/Bundle/*/test/src/**.php'

Expand All @@ -35,6 +34,11 @@ parameters:
- '/Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface/'
- '/Call to an undefined method Mockery\\ExpectationInterface|Mockery\\HigherOrderMessage::/'

# PhpSpec related errors
- '/Access to an undefined property spec\\/'
- '/Call to an undefined method spec\\/'
- '/Call to an undefined static method spec\\/'

# These packages aren't in require-dev of the global package
- '/Class Doctrine\\Bundle\\MongoDBBundle/'
- '/Class Doctrine\\Bundle\\PHPCRBundle/'
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/spec/Service/Mocker/MockerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace spec\Sylius\Behat;
namespace spec\Sylius\Behat\Service\Mocker;

use Mockery\MockInterface;
use Payum\Core\Bridge\Guzzle\HttpClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace spec\Sylius\Behat;
namespace spec\Sylius\Behat\Service\Setter;

use PhpSpec\ObjectBehavior;
use Sylius\Behat\Service\Setter\ChannelContextSetter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function it_validates_attribute_value_based_on_their_type(
$attributeValue->getAttribute()->willReturn($attribute);
$attribute->getConfiguration()->willReturn(['min' => 2, 'max' => 255]);

$attributeType->validate($attributeValue, Argument::any(ExecutionContextInterface::class), ['min' => 2, 'max' => 255])->shouldBeCalled();
$attributeType->validate($attributeValue, Argument::type(ExecutionContextInterface::class), ['min' => 2, 'max' => 255])->shouldBeCalled();

$this->validate($attributeValue, $attributeValueConstraint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function it_validates_attribute_based_on_its_type_and_set_it_as_required_if_its_
$localeProvider->getDefaultLocaleCode()->willReturn('en_US');
$attributeValue->getLocaleCode()->willReturn('pl');

$attributeType->validate($attributeValue, Argument::any(ExecutionContextInterface::class), ['min' => 2, 'max' => 255])->shouldBeCalled();
$attributeType->validate($attributeValue, Argument::type(ExecutionContextInterface::class), ['min' => 2, 'max' => 255])->shouldBeCalled();

$this->validate($attributeValue, $attributeValueConstraint);
}
Expand All @@ -75,7 +75,7 @@ function it_validates_attribute_value_based_on_its_type_and_do_not_set_it_as_req
$localeProvider->getDefaultLocaleCode()->willReturn('en_US');
$attributeValue->getLocaleCode()->willReturn('en_US');

$attributeType->validate($attributeValue, Argument::any(ExecutionContextInterface::class), ['min' => 2, 'max' => 255, 'required' => true])->shouldBeCalled();
$attributeType->validate($attributeValue, Argument::type(ExecutionContextInterface::class), ['min' => 2, 'max' => 255, 'required' => true])->shouldBeCalled();

$this->validate($attributeValue, $attributeValueConstraint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class AddToCartCommandSpec extends ObjectBehavior
{
function let(OrderInterface $order, OrderItemInterface $orderItem): void
{
$this->beConstructedThrough('createWithCartAndCartItem', [$order, $orderItem]);
$this->beConstructedWith($order, $orderItem);
}

function it_is_add_cart_item_command(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace spec\Sylius\Bundle\ThemeBundle\Translation\Provider;
namespace spec\Sylius\Bundle\ThemeBundle\Translation\Provider\Loader;

use PhpSpec\ObjectBehavior;
use Sylius\Bundle\ThemeBundle\Translation\Provider\Loader\TranslatorLoaderProviderInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace spec\Sylius\Bundle\ThemeBundle\Translation\Provider;
namespace spec\Sylius\Bundle\ThemeBundle\Translation\Provider\Resource;

use PhpSpec\ObjectBehavior;
use Sylius\Bundle\ThemeBundle\Translation\Provider\Resource\TranslatorResourceProviderInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace spec\Sylius\Bundle\ThemeBundle\Translation\Provider;
namespace spec\Sylius\Bundle\ThemeBundle\Translation\Provider\Resource;

use PhpSpec\ObjectBehavior;
use Sylius\Bundle\ThemeBundle\HierarchyProvider\ThemeHierarchyProviderInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace spec\Sylius\Bundle\ThemeBundle\Translation\Provider;
namespace spec\Sylius\Bundle\ThemeBundle\Translation\Provider\Resource;

use PhpSpec\ObjectBehavior;
use Sylius\Bundle\ThemeBundle\Translation\Provider\Resource\TranslatorResourceProviderInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace spec\Sylius\Bundle\ThemeBundle\Translation\Provider;
namespace spec\Sylius\Bundle\ThemeBundle\Translation\Resource;

use PhpSpec\ObjectBehavior;
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace spec\Sylius\Bundle\ThemeBundle\Translation\Provider;
namespace spec\Sylius\Bundle\ThemeBundle\Translation\Resource;

use PhpSpec\ObjectBehavior;
use Sylius\Bundle\ThemeBundle\Translation\Resource\TranslationResourceInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace spec\Sylius\Component\Core\Context;
namespace spec\Sylius\Component\Core\Locale\Context;

use PhpSpec\ObjectBehavior;
use Sylius\Component\Channel\Context\ChannelContextInterface;
Expand Down