Skip to content

Commit

Permalink
bug #10059 Cover specs with PHPStan (pamil)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.2 branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | 1.2
| Bug fix?        | yes
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | -
| License         | MIT

Tried to add `proget-hq/phpstan-phpspec` to our PHPStan but ended up reporting proget-hq/phpstan-phpspec#8 and covering our specs with PHPStan and some ignored errors.

This led me to find over ten specs which were not run due to class name/namespace/filename mismatches and some wrong `Argument::` calls in specs.


Commits
-------

1376307 Update PhpSpec to ^5.0
7913eeb Setup spec paths in autoload-dev in the main package
6b9357d Fix spec classnames / filenames mismatches
8994f2c Make PHPStan for specs passing
6cee10b Make PhpSpec passing after fixing PHPStan warnings
a007c90 Remove PHPStan extension for Symfony
  • Loading branch information
pamil authored Jan 2, 2019
2 parents 495bcca + a007c90 commit 60d4175
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 22 deletions.
57 changes: 53 additions & 4 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,10 +90,9 @@
"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",
"phpstan/phpstan-webmozart-assert": "^0.10",
"phpunit/phpunit": "^6.5",
"stripe/stripe-php": "^4.1",
Expand Down Expand Up @@ -190,7 +189,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/"
},
"classmap": ["app/AppKernel.php", "app/AppCache.php", "app/TestAppKernel.php"]
},
Expand Down
10 changes: 5 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
includes:
- vendor/phpstan/phpstan-doctrine/extension.neon
- vendor/phpstan/phpstan-symfony/extension.neon
- vendor/phpstan/phpstan-webmozart-assert/extension.neon

parameters:
reportUnmatchedIgnoredErrors: false

symfony:
container_xml_path: var/cache/dev/appDevDebugProjectContainer.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 +30,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

0 comments on commit 60d4175

Please sign in to comment.