Merge branch '1.9'

* 1.9:
  [ApiBundle] Add README file with testing instructions
  [ApiBundle] Remove setting APP_DEBUG variable for PHPUnit
  [Api] Refactor fetching id from IRI converter to direct object
  [ApiBundle] Move unit tests of test application to src directory
  [ApiBundle] Revert changes in RouteNameResolver and PathPrefixProvider
  [ApiBundle] Refactor directories and namespaces of test application
  [ApiBundle] Update composer in test application
  [ApiBundle] Update .gitignore file in test application
  [ApiBundle] Simplify configs of test application
  Add tests for Taxon and add fixes
  Add tests for chceking relations and iris on api resource
  Add test and configuration for overwriting apiPlatform resources
  Add test for resource type entity
  Add test for new not admin api resource by loged admin
  Add test entity and api_platform overwriting config
  Add test app for ApiBundle
This commit is contained in:
Kamil Kokot 2021-03-01 09:26:13 +00:00
commit 2d52274713
47 changed files with 1536 additions and 2 deletions

View file

@ -6,6 +6,10 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../etc/bash/common.lib.sh"
test_package() {
local exit_code=0
if [ "$(package_path_to_package_name "$1")" == "ApiBundle" ] ; then
(cd src/Sylius/Bundle/ApiBundle/test && bin/console doctrine:schema:update --force -e test)
fi
print_header "Testing" "$(package_path_to_package_name "$1")"
cd "$1" 2>/dev/null

View file

@ -12,6 +12,7 @@ parameters:
excludes_analyse:
# Test dependencies
- '**/spec/**.php'
- '**/Bundle/*/test/**.php'
- '**/Bundle/*/test/app/**.php'
- '**/Bundle/*/test/src/**.php'
- '**/Bundle/*/Tests/Functional/app/**.php'

View file

@ -22,6 +22,7 @@
<directory name="src/Sylius/Bundle/AdminApiBundle/Tests" />
<directory name="src/Sylius/Bundle/ApiBundle/spec" />
<directory name="src/Sylius/Bundle/ApiBundle/Tests" />
<directory name="src/Sylius/Bundle/ApiBundle/test" />
<directory name="src/Sylius/Bundle/AdminBundle/spec" />
<directory name="src/Sylius/Bundle/AdminBundle/Tests" />
<directory name="src/Sylius/Bundle/AttributeBundle/spec" />

View file

@ -1,3 +1,4 @@
/vendor/
/composer.lock
/.phpunit.result.cache

View file

@ -0,0 +1,64 @@
SyliusApiBundle
================
Unified API for Sylius eCommerce.
Sylius
------
![Sylius](https://demo.sylius.com/assets/shop/img/logo.png)
Sylius is an Open Source eCommerce solution built from decoupled components with powerful API and the highest quality code. [Read more on sylius.com](https://sylius.com).
Documentation
-------------
Documentation is available on [**docs.sylius.com**](https://docs.sylius.com).
Contributing
------------
[This page](https://docs.sylius.com/en/latest/contributing/index.html) contains all the information about contributing to Sylius.
Follow Sylius' Development
--------------------------
If you want to keep up with the updates and latest features, follow us on the following channels:
* [Official Blog](https://sylius.com/blog)
* [Sylius on Twitter](https://twitter.com/Sylius)
* [Sylius on Facebook](https://facebook.com/SyliusEcommerce)
Bug tracking
------------
Sylius uses [GitHub issues](https://github.com/Sylius/Sylius/issues).
If you have found bug, please create an issue.
MIT License
-----------
License can be found [here](https://github.com/Sylius/Sylius/blob/master/LICENSE).
Authors
-------
The bundle was originally created by [Paweł Jędrzejewski](https://pjedrzejewski.com).
See the list of [contributors](https://github.com/Sylius/Sylius/contributors).
Testing
-----------------------
To test locally, run commands:
```bash
(cd src/Sylius/Bundle/ApiBundle && composer install)
(cd src/Sylius/Bundle/ApiBundle/test && bin/console doctrine:database:create -e test)
(cd src/Sylius/Bundle/ApiBundle/test && bin/console doctrine:schema:update --force -e test)
(cd src/Sylius/Bundle/ApiBundle/test && bin/console assets:install public)
(cd src/Sylius/Bundle/ApiBundle/test && APP_ENV=test symfony serve)
```
To run tests:
```bash
(cd src/Sylius/Bundle/ApiBundle && vendor/bin/phpunit)
```

View file

@ -30,10 +30,17 @@
"lexik/jwt-authentication-bundle": "^2.6"
},
"require-dev": {
"lexik/jwt-authentication-bundle": "^2.6",
"matthiasnoback/symfony-config-test": "^4.2",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"nelmio/alice": "^3.6",
"phpspec/phpspec": "^7.0",
"phpunit/phpunit": "^8.5"
"phpunit/phpunit": "^8.5",
"symfony/browser-kit": "^4.4 || ^5.2",
"symfony/debug-bundle": "^4.4 || ^5.2",
"symfony/dotenv": "^4.4 || ^5.2",
"symfony/http-client": "^5.2",
"theofidry/alice-data-fixtures": "^1.4"
},
"extra": {
"branch-alias": {
@ -52,7 +59,8 @@
"autoload-dev": {
"psr-4": {
"Sylius\\Bundle\\ApiBundle\\spec\\": "spec/",
"Sylius\\Bundle\\ApiBundle\\Tests\\": "Tests/"
"Sylius\\Bundle\\ApiBundle\\Tests\\": "Tests/",
"Sylius\\Bundle\\ApiBundle\\Application\\": "test/src/"
}
},
"repositories": [

View file

View file

@ -4,9 +4,18 @@
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.5/phpunit.xsd"
colors="true"
>
<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_CLASS" value="Sylius\Bundle\ApiBundle\Application\Kernel" />
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" />
<server name="DATABASE_URL" value="sqlite:///%kernel.project_dir%/var/db.sql" />
</php>
<testsuites>
<testsuite name="SyliusApiBundle Test Suite">
<directory>./Tests/</directory>
<directory>./test/src/Tests/</directory>
</testsuite>
</testsuites>

View file

@ -0,0 +1,5 @@
###> symfony/framework-bundle ###
APP_ENV=dev
APP_DEBUG=1
APP_SECRET=EDITME
###< symfony/framework-bundle ###

View file

@ -0,0 +1 @@
KERNEL_CLASS='Sylius\Bundle\ApiBundle\Application\Kernel'

View file

@ -0,0 +1,47 @@
/public/assets
/public/css
/public/js
/public/media
/public/build
!/public/media/image/.gitkeep
/bin/symfony_requirements
/docs/.doctrees
/composer.lock
/node_modules
/etc/build/*
!/etc/build/.gitignore
/behat.yml
/phpspec.yml
# Symfony CLI https://symfony.com/doc/current/setup/symfony_server.html#different-php-settings-per-project
/.php-version
/php.ini
###> symfony/framework-bundle ###
.env.*.local
.env.local
.env.local.php
/public/bundles
/var/
/vendor/
###< symfony/framework-bundle ###
###> friendsofphp/php-cs-fixer ###
/.php_cs
/.php_cs.cache
###< friendsofphp/php-cs-fixer ###
###> phpunit/phpunit ###
/phpunit.xml
/.phpunit.result.cache
###< phpunit/phpunit ###
###> lexik/jwt-authentication-bundle ###
/Application/config/jwt/private.pem
/Application/config/jwt/public.pem
###< lexik/jwt-authentication-bundle ###

View file

@ -0,0 +1,47 @@
#!/usr/bin/env php
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Sylius\Bundle\ApiBundle\Application\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\ErrorHandler\Debug;
set_time_limit(0);
require __DIR__ . '/../../vendor/autoload.php';
if (!class_exists(Application::class)) {
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
}
$input = new ArgvInput();
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
}
if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}
require dirname(__DIR__) . '/config/bootstrap.php';
if ($_SERVER['APP_DEBUG']) {
umask(0000);
if (class_exists(Debug::class)) {
Debug::enable();
}
}
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$application = new Application($kernel);
$application->run($input);

View file

@ -0,0 +1,45 @@
<?xml version="1.0" ?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<resources xmlns="https://api-platform.com/schema/metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata https://api-platform.com/schema/metadata/metadata-2.0.xsd"
>
<resource class="Sylius\Bundle\ApiBundle\Application\Entity\Foo" shortName="Foo">
<collectionOperations>
<collectionOperation name="get">
<attribute name="method">GET</attribute>
<attribute name="normalization_context">
<attribute name="groups">foo:read</attribute>
</attribute>
</collectionOperation>
<collectionOperation name="post">
<attribute name="method">POST</attribute>
<attribute name="denormalization_context">
<attribute name="groups">foo:create</attribute>
</attribute>
</collectionOperation>
</collectionOperations>
<itemOperations>
<itemOperation name="get">
<attribute name="method">GET</attribute>
<attribute name="normalization_context">
<attribute name="groups">foo:read</attribute>
</attribute>
</itemOperation>
</itemOperations>
<property name="id" identifier="true" writable="false" />
<property name="name" writable="true" />
<property name="owner" writable="true" readable="true" />
<property name="fooSyliusResource" writable="true" readable="true" />
</resource>
</resources>

View file

@ -0,0 +1,43 @@
<?xml version="1.0" ?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<resources xmlns="https://api-platform.com/schema/metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata https://api-platform.com/schema/metadata/metadata-2.0.xsd"
>
<resource class="Sylius\Bundle\ApiBundle\Application\Entity\FooSyliusResource" shortName="FooSyliusResource">
<collectionOperations>
<collectionOperation name="get">
<attribute name="method">GET</attribute>
<attribute name="normalization_context">
<attribute name="groups">foo-sylius-resource:read</attribute>
</attribute>
</collectionOperation>
<collectionOperation name="post">
<attribute name="method">POST</attribute>
<attribute name="denormalization_context">
<attribute name="groups">foo-sylius-resource:create</attribute>
</attribute>
</collectionOperation>
</collectionOperations>
<itemOperations>
<itemOperation name="get">
<attribute name="method">GET</attribute>
<attribute name="normalization_context">
<attribute name="groups">foo-sylius-resource:read</attribute>
</attribute>
</itemOperation>
</itemOperations>
<property name="id" identifier="true" writable="false" />
<property name="name" writable="true" />
</resource>
</resources>

View file

@ -0,0 +1,58 @@
<?xml version="1.0" ?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<resources xmlns="https://api-platform.com/schema/metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata https://api-platform.com/schema/metadata/metadata-2.0.xsd"
>
<resource class="%sylius.model.promotion.class%" shortName="Promotion">
<attribute name="route_prefix">custom</attribute>
<attribute name="validation_groups">sylius</attribute>
<collectionOperations>
<collectionOperation name="admin_get">
<attribute name="method">GET</attribute>
<attribute name="normalization_context">
<attribute name="groups">admin:promotion:read</attribute>
</attribute>
</collectionOperation>
</collectionOperations>
<itemOperations>
<itemOperation name="admin_get">
<attribute name="method">GET</attribute>
<attribute name="normalization_context">
<attribute name="groups">admin:promotion:read</attribute>
</attribute>
</itemOperation>
<itemOperation name="admin_delete">
<attribute name="method">DELETE</attribute>
</itemOperation>
</itemOperations>
<property name="id" identifier="true" writable="false" />
<property name="name" readable="true" />
<property name="description" readable="true" />
<property name="priority" readable="true" />
<property name="exclusive" readable="true" />
<property name="usageLimit" readable="true" />
<property name="startsAt" readable="true" />
<property name="endsAt" readable="true" />
<property name="couponBased" readable="true" />
<property name="coupons" readable="true" />
<property name="rules" readable="true" />
<property name="actions" readable="true" />
<property name="channels" readable="true" />
</resource>
</resources>

View file

@ -0,0 +1,67 @@
<?xml version="1.0" ?>
<resources xmlns="https://api-platform.com/schema/metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata https://api-platform.com/schema/metadata/metadata-2.0.xsd"
>
<resource class="%sylius.model.taxon.class%" shortName="Taxon">
<attribute name="validation_groups">sylius</attribute>
<collectionOperations>
<collectionOperation name="admin_get">
<attribute name="method">GET</attribute>
<attribute name="path">/admin/taxons</attribute>
<attribute name="normalization_context">
<attribute name="groups">admin:taxon:read</attribute>
</attribute>
</collectionOperation>
<collectionOperation name="admin_post">
<attribute name="method">POST</attribute>
<attribute name="path">/admin/taxons</attribute>
<attribute name="denormalization_context">
<attribute name="groups">admin:taxon:create</attribute>
</attribute>
</collectionOperation>
<collectionOperation name="shop_get">
<attribute name="method">GET</attribute>
<attribute name="path">/shop/taxons</attribute>
<attribute name="normalization_context">
<attribute name="groups">shop:taxon:read</attribute>
</attribute>
</collectionOperation>
</collectionOperations>
<itemOperations>
<itemOperation name="admin_get">
<attribute name="method">GET</attribute>
<attribute name="path">/admin/taxons/{id}</attribute>
<attribute name="normalization_context">
<attribute name="groups">admin:taxon:read</attribute>
</attribute>
</itemOperation>
<itemOperation name="admin_put">
<attribute name="method">PUT</attribute>
<attribute name="path">/admin/taxons/{id}</attribute>
<attribute name="denormalization_context">
<attribute name="groups">admin:taxon:update</attribute>
</attribute>
</itemOperation>
<itemOperation name="shop_get">
<attribute name="method">GET</attribute>
<attribute name="path">/shop/taxons/{id}</attribute>
<attribute name="normalization_context">
<attribute name="groups">shop:taxon:read</attribute>
</attribute>
</itemOperation>
</itemOperations>
<property name="id" identifier="true" writable="false" readable="true" />
<property name="code" identifier="false" required="true" />
<property name="translations" readable="true" writable="true" />
<property name="type" readable="true" writable="true" />
</resource>
</resources>

View file

@ -0,0 +1,22 @@
<?php
use Symfony\Component\Dotenv\Dotenv;
require __DIR__ . '/../../vendor/autoload.php';
// Load cached env vars if the .env.local.php file exists
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
$envLocalPhpPath = dirname(__DIR__) . '/.env.local.php';
if (is_array($env = @include $envLocalPhpPath)) {
$_SERVER += $env;
$_ENV += $env;
} elseif (!class_exists(Dotenv::class)) {
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
} else {
// load all the .env files
(new Dotenv())->loadEnv(dirname(__DIR__) . '/.env');
}
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';

View file

@ -0,0 +1,62 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Sylius\Bundle\OrderBundle\SyliusOrderBundle::class => ['all' => true],
Sylius\Bundle\MoneyBundle\SyliusMoneyBundle::class => ['all' => true],
Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle::class => ['all' => true],
Sylius\Bundle\LocaleBundle\SyliusLocaleBundle::class => ['all' => true],
Sylius\Bundle\ProductBundle\SyliusProductBundle::class => ['all' => true],
Sylius\Bundle\ChannelBundle\SyliusChannelBundle::class => ['all' => true],
Sylius\Bundle\AttributeBundle\SyliusAttributeBundle::class => ['all' => true],
Sylius\Bundle\TaxationBundle\SyliusTaxationBundle::class => ['all' => true],
Sylius\Bundle\ShippingBundle\SyliusShippingBundle::class => ['all' => true],
Sylius\Bundle\PaymentBundle\SyliusPaymentBundle::class => ['all' => true],
Sylius\Bundle\MailerBundle\SyliusMailerBundle::class => ['all' => true],
Sylius\Bundle\PromotionBundle\SyliusPromotionBundle::class => ['all' => true],
Sylius\Bundle\AddressingBundle\SyliusAddressingBundle::class => ['all' => true],
Sylius\Bundle\InventoryBundle\SyliusInventoryBundle::class => ['all' => true],
Sylius\Bundle\TaxonomyBundle\SyliusTaxonomyBundle::class => ['all' => true],
Sylius\Bundle\UserBundle\SyliusUserBundle::class => ['all' => true],
Sylius\Bundle\CustomerBundle\SyliusCustomerBundle::class => ['all' => true],
Sylius\Bundle\UiBundle\SyliusUiBundle::class => ['all' => true],
Sylius\Bundle\ReviewBundle\SyliusReviewBundle::class => ['all' => true],
Sylius\Bundle\CoreBundle\SyliusCoreBundle::class => ['all' => true],
Sylius\Bundle\ResourceBundle\SyliusResourceBundle::class => ['all' => true],
Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
winzou\Bundle\StateMachineBundle\winzouStateMachineBundle::class => ['all' => true],
Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true],
Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle::class => ['all' => true],
JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true],
Knp\Bundle\GaufretteBundle\KnpGaufretteBundle::class => ['all' => true],
Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true],
Payum\Bundle\PayumBundle\PayumBundle::class => ['all' => true],
Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true],
BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Sylius\Bundle\FixturesBundle\SyliusFixturesBundle::class => ['all' => true],
Sylius\Bundle\PayumBundle\SyliusPayumBundle::class => ['all' => true],
Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true],
SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true],
SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true],
ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
];

View file

@ -0,0 +1,67 @@
imports:
- { resource: "@SyliusCoreBundle/Resources/config/app/config.yml" }
- { resource: "@SyliusApiBundle/Resources/config/app/config.yaml" }
- { resource: "security.yaml" }
parameters:
locale: en_US
database_driver: pdo_sqlite
database_path: "%kernel.project_dir%/var/db.sql"
api_platform:
mapping:
paths:
- '%kernel.api_bundle_path%/Resources/config/api_resources'
- '%kernel.project_dir%/config/api_resources'
framework:
assets: ~
secret: "ch4mb3r0f5ecr3ts"
default_locale: "%locale%"
session:
handler_id: ~
storage_id: session.storage.mock_file
http_method_override: true
test: ~
serializer:
mapping:
paths: ['%kernel.project_dir%/config/serialization']
doctrine_migrations:
storage:
table_storage:
table_name: sylius_migrations
doctrine:
dbal:
driver: "%database_driver%"
path: "%database_path%"
charset: UTF8
orm:
entity_managers:
default:
mappings:
test:
mapping: true
type: xml
dir: '%kernel.project_dir%/config/doctrine'
alias: ~
prefix: Sylius\Bundle\ApiBundle\Application\Entity
is_bundle: false
lexik_jwt_authentication:
secret_key: "%kernel.project_dir%/config/jwt/private-test.pem"
public_key: "%kernel.project_dir%/config/jwt/public-test.pem"
pass_phrase: "ALL_THAT_IS_GOLD_DOES_NOT_GLITTER_NOT_ALL_THOSE_WHO_WANDER_ARE_LOST"
sylius_taxonomy:
resources:
taxon:
classes:
model: Sylius\Bundle\ApiBundle\Application\Entity\Taxon
sylius_resource:
resources:
test.foo_sylius_resource:
classes:
model: Sylius\Bundle\ApiBundle\Application\Entity\FooSyliusResource

View file

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping">
<entity name="Sylius\Bundle\ApiBundle\Application\Entity\Foo" table="foo">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>
<field name="name" column="name" type="string" />
<many-to-one field="owner" target-entity="Sylius\Component\Core\Model\AdminUserInterface">
<join-column name="owner_id" referenced-column-name="id" />
</many-to-one>
<many-to-one field="fooSyliusResource" target-entity="Sylius\Bundle\ApiBundle\Application\Entity\FooSyliusResource">
<join-column name="foo_sylius_resource_id" referenced-column-name="id" />
</many-to-one>
</entity>
</doctrine-mapping>

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping">
<entity name="Sylius\Bundle\ApiBundle\Application\Entity\FooSyliusResource" table="foo_sylius_resource">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>
<field name="name" column="name" type="string" />
</entity>
</doctrine-mapping>

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping">
<entity name="Sylius\Bundle\ApiBundle\Application\Entity\Taxon" table="sylius_taxon">
<field name="type" column="type" type="string" />
</entity>
</doctrine-mapping>

View file

@ -0,0 +1,8 @@
Sylius\Component\Core\Model\AdminUser:
admin:
plainPassword: sylius
roles: [ROLE_API_ACCESS]
enabled: true
email: api@sylius.com
username: sylius
localeCode: en_US

View file

@ -0,0 +1,20 @@
Sylius\Component\Core\Model\Channel:
channel_web:
code: "WEB"
name: "Web Channel"
hostname: "localhost"
description: "Lorem ipsum"
baseCurrency: "@currency1"
defaultLocale: "@locale"
locales: ["@locale"]
color: "black"
enabled: true
taxCalculationStrategy: "order_items_based"
Sylius\Component\Currency\Model\Currency:
currency1:
code: "USD"
Sylius\Component\Locale\Model\Locale:
locale:
code: "en_US"

View file

@ -0,0 +1,13 @@
Sylius\Bundle\ApiBundle\Application\Entity\FooSyliusResource:
fooSyliusResource3:
name: FooSyliusResource3
Sylius\Bundle\ApiBundle\Application\Entity\Foo:
foo1:
name: Foo0
owner: '@admin'
fooSyliusResource: '@fooSyliusResource3'
foo2:
name: Foo1
owner: '@admin'
fooSyliusResource: '@fooSyliusResource3'

View file

@ -0,0 +1,5 @@
Sylius\Bundle\ApiBundle\Application\Entity\FooSyliusResource:
fooSyliusResource1:
name: FooSyliusResource1
fooSyliusResource2:
name: FooSyliusResource2

View file

@ -0,0 +1,5 @@
Sylius\Component\Core\Model\Promotion:
sunday_promotion:
code: Sunday
name: Sunday promotion
couponBased: false

View file

@ -0,0 +1,21 @@
Sylius\Bundle\ApiBundle\Application\Entity\Taxon:
category:
code: "category"
mugs:
code: "mugs"
parent: "@category"
stickers:
code: "stickers"
parent: "@category"
books:
code: "books"
parent: "@category"
t-shirts:
code: "t-shirts"
parent: "@category"
men:
code: "men"
parent: "@t-shirts"
women:
code: "women"
parent: "@t-shirts"

View file

@ -0,0 +1,54 @@
-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIJnzBJBgkqhkiG9w0BBQ0wPDAbBgkqhkiG9w0BBQwwDgQIpffLoj6VVIMCAggA
MB0GCWCGSAFlAwQBKgQQJQevAkSbcnWJ4fvpizjjYwSCCVA1ejQGYuM7aajTE6kP
0AoRFeCfJ2BB5qR+dVHvBBT3BamzSG1ImFUrpkMvyABwtOTyI0E+LcIu086wtDiG
KoY1OX9oICyLk9h3F255BCKOpG3LA3tNxlnW7tsbGg15/AbE1CoiptB0Lwiuo+A7
UCLyNewqhk2QJdj2YK4Hy/R2UKA+6fH+xx0oWZTB8DlOL9pxh3lRGULNsXaph2SV
9l2g+YZePvMajOAGe3h5s66BUEtFKMPJno8gMy7GlCnJxpjlXFf5kCuoTRQYCUQE
LmWIlUaR5wE0XgYybGHilnicnUmlRQAw2L2VeWTmEKuDtq8qqk3ByaAO8moN76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iIUEeTWLtc
BnY0F3Gi+gFvx9iSJPelL6GFJsDHF3KZRMBLyIlVGg6KEkFFa+UzCXwRpRRjdfqg
PMgejDSbZ2xvKvgtvLhjVCXFgtBQBnu+HwoxEspU2F1YYz2PNkfI1azzLTdwKF9s
mUerk2QfvjETmjQfmbWKRTffYBuN/nsh8/1sUvVDKgIMLeJCtCQoiCGtG3kfp4bd
fZ2WbdthFRSYG2waBMUV5fRo+VvvmWH1iQJqmv2K5S8bUXYymOibxlOoMk1JnjLz
n5cVv3kfl1AB73rUyDgAS09PMYqbKPXDkn1DPlRvu1CkvDcKOHHpPRnuXDmUuyO+
2dbloH/Xb8uzyg+CbcAcadlMRaYLlvm4TGDV6epIsZLvJnAcy3Q98mdATw5JjOTL
x56k5+HGoKBelUWzc3aOVxxUZ3EaUTMI+8bBDtNJH/ZXMGV2oVPITM3qAdpELqNu
qR+Ds4NK5xxsiKnt2slfmwECAwEAAQ==
-----END PUBLIC KEY-----

View file

@ -0,0 +1,3 @@
sylius_api:
resource: "@SyliusApiBundle/Resources/config/routing.yml"
prefix: "%sylius.security.new_api_route%"

View file

@ -0,0 +1,56 @@
security:
always_authenticate_before_granting: true
providers:
sylius_api_admin_user_provider:
id: sylius.admin_user_provider.email_or_name_based
sylius_api_shop_user_provider:
id: sylius.shop_user_provider.email_or_name_based
encoders:
sha512: sha512
Sylius\Component\User\Model\UserInterface: sha512
firewalls:
new_api_admin_user:
pattern: "%sylius.security.new_api_admin_regex%/.*"
provider: sylius_api_admin_user_provider
stateless: true
anonymous: true
json_login:
check_path: "%sylius.security.new_api_admin_route%/authentication-token"
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
new_api_shop_user:
pattern: "%sylius.security.new_api_shop_regex%/.*"
provider: sylius_api_shop_user_provider
stateless: true
anonymous: true
json_login:
check_path: "%sylius.security.new_api_shop_route%/authentication-token"
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
access_control:
- { path: "%sylius.security.new_api_admin_regex%/.*", role: ROLE_API_ACCESS }
- { path: "%sylius.security.new_api_admin_route%/authentication-token", role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: "%sylius.security.new_api_user_account_regex%/.*", role: ROLE_USER }
- { path: "%sylius.security.new_api_shop_route%/authentication-token", role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: "%sylius.security.new_api_shop_regex%/.*", role: IS_AUTHENTICATED_ANONYMOUSLY }
sylius_user:
encoder: sha512

View file

@ -0,0 +1,35 @@
<?xml version="1.0" ?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<serializer xmlns="http://symfony.com/schema/dic/serializer-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
>
<class name="Sylius\Bundle\ApiBundle\Application\Entity\Foo">
<attribute name="id">
<group>foo:read</group>
</attribute>
<attribute name="name">
<group>foo:read</group>
<group>foo:create</group>
</attribute>
<attribute name="owner">
<group>foo:read</group>
<group>foo:create</group>
</attribute>
<attribute name="fooSyliusResource">
<group>foo:read</group>
<group>foo:create</group>
</attribute>
</class>
</serializer>

View file

@ -0,0 +1,27 @@
<?xml version="1.0" ?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<serializer xmlns="http://symfony.com/schema/dic/serializer-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
>
<class name="Sylius\Bundle\ApiBundle\Application\Entity\FooSyliusResource">
<attribute name="id">
<group>foo-sylius-resource:read</group>
</attribute>
<attribute name="name">
<group>foo-sylius-resource:read</group>
<group>foo-sylius-resource:create</group>
</attribute>
</class>
</serializer>

View file

@ -0,0 +1,27 @@
<?xml version="1.0" ?>
<serializer xmlns="http://symfony.com/schema/dic/serializer-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
>
<class name="Sylius\Bundle\ApiBundle\Application\Entity\Taxon">
<attribute name="id">
<group>admin:taxon:read</group>
<group>shop:taxon:read</group>
</attribute>
<attribute name="code">
<group>admin:taxon:read</group>
<group>shop:taxon:read</group>
<group>admin:taxon:create</group>
<group>admin:taxon:update</group>
</attribute>
<attribute name="translations">
<group>admin:taxon:read</group>
<group>shop:taxon:read</group>
</attribute>
<attribute name="type">
<group>admin:taxon:read</group>
<group>shop:taxon:read</group>
</attribute>
</class>
</serializer>

View file

@ -0,0 +1,4 @@
<?php
$projectDir = $container->getParameter('kernel.project_dir');
$container->setParameter('kernel.api_bundle_path', str_replace('/test', '', $projectDir));

View file

@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
use Sylius\Bundle\ApiBundle\Application\Kernel;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;
require dirname(__DIR__) . '/config/bootstrap.php';
if ($_SERVER['APP_DEBUG']) {
umask(0000);
Debug::enable();
}
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts([$trustedHosts]);
}
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

View file

@ -0,0 +1,71 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* 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\Bundle\ApiBundle\Application\Entity;
use Sylius\Component\Core\Model\AdminUserInterface;
class Foo
{
/** @var int */
private $id;
/** @var string */
private $name;
/** @var AdminUserInterface */
private $owner;
/** @var FooSyliusResource */
private $fooSyliusResource;
public function getId(): int
{
return $this->id;
}
public function setId(int $id): void
{
$this->id = $id;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): void
{
$this->name = $name;
}
public function getOwner(): AdminUserInterface
{
return $this->owner;
}
public function setOwner(AdminUserInterface $owner): void
{
$this->owner = $owner;
}
public function getFooSyliusResource(): FooSyliusResource
{
return $this->fooSyliusResource;
}
public function setFooSyliusResource(FooSyliusResource $fooSyliusResource): void
{
$this->fooSyliusResource = $fooSyliusResource;
}
}

View file

@ -0,0 +1,45 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* 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\Bundle\ApiBundle\Application\Entity;
use Sylius\Component\Resource\Model\ResourceInterface;
class FooSyliusResource implements ResourceInterface
{
/** @var int */
private $id;
/** @var string */
private $name;
public function getId()
{
return $this->id;
}
public function setId(int $id): void
{
$this->id = $id;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): void
{
$this->name = $name;
}
}

View file

@ -0,0 +1,39 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* 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\Bundle\ApiBundle\Application\Entity;
use Sylius\Component\Core\Model\Taxon as BaseTaxon;
class Taxon extends BaseTaxon
{
/** @var string */
private $type;
public function __construct()
{
parent::__construct();
$this->type = 'default';
}
public function setType(?string $type): void
{
$this->type = $type;
}
public function getType(): string
{
return $this->type;
}
}

View file

@ -0,0 +1,80 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* 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\Bundle\ApiBundle\Application;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\DelegatingLoader;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\Config\FileLocator;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
use Webmozart\Assert\Assert;
final class Kernel extends BaseKernel
{
use MicroKernelTrait;
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
public function getCacheDir(): string
{
return $this->getProjectDir() . '/var/cache/' . $this->environment;
}
public function getLogDir(): string
{
return $this->getProjectDir() . '/var/log';
}
public function getProjectDir(): string
{
return parent::getProjectDir() . '/test';
}
public function registerBundles(): iterable
{
$bundlesPath = $this->getProjectDir() . '/config/bundles.php';
$contents = require $bundlesPath;
foreach ($contents as $class => $envs) {
if (isset($envs['all']) || isset($envs[$this->environment])) {
yield new $class();
}
}
}
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
$container->setParameter('container.dumper.inline_class_loader', true);
$loader->load($this->getProjectDir() . '/config/config.yaml');
$loader->load($this->getProjectDir() . '/config/services.php');
}
protected function configureRoutes(RouteCollectionBuilder $routes): void
{
$routes->import($this->getProjectDir() . '/config/routing.yaml', '/');
}
}

View file

@ -0,0 +1,80 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* 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\Bundle\ApiBundle\Application\Tests;
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
final class FooSyliusResourceTest extends ApiTestCase
{
use SetUpTestsTrait;
public function setUp(): void
{
$this->setFixturesFiles(['test/config/fixtures/foo_sylius_resource.yaml']);
$this->setUpTest();
}
/**
* @test
*/
public function it_allows_to_get_collection_as_a_logged_in_administrator_on_new_not_admin_resource(): void
{
$response = static::createClient()->request(
'GET',
'api/v2/foo-sylius-resources',
['auth_bearer' => $this->JWTAdminUserToken]
);
$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$objects = json_decode($response->getContent(), true)['hydra:member'];
$this->assertSame('FooSyliusResource1', $objects[0]['name']);
$this->assertSame('FooSyliusResource2', $objects[1]['name']);
}
/**
* @test
*/
public function it_allows_to_get_collection_as_a_visitor(): void
{
$response = static::createClient()->request('GET', 'api/v2/foo-sylius-resources');
$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$objects = json_decode($response->getContent(), true)['hydra:member'];
$this->assertSame('FooSyliusResource1', $objects[0]['name']);
$this->assertSame('FooSyliusResource2', $objects[1]['name']);
}
/**
* @test
*/
public function it_allows_to_post_as_a_visitor(): void
{
$response = static::createClient()->request(
'POST',
'api/v2/foo-sylius-resources',
['json' => ["name" => "FooSyliusResourcePost"]]
);
$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertSame('FooSyliusResourcePost', json_decode($response->getContent(), true)['name']);
}
}

View file

@ -0,0 +1,120 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* 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\Bundle\ApiBundle\Application\Tests;
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
use Sylius\Bundle\ApiBundle\Application\Entity\Foo;
use Sylius\Bundle\ApiBundle\Application\Entity\FooSyliusResource;
use Sylius\Component\Core\Model\AdminUser;
use Symfony\Contracts\HttpClient\ResponseInterface;
final class FooTest extends ApiTestCase
{
use SetUpTestsTrait;
public function setUp(): void
{
$this->setFixturesFiles(['test/config/fixtures/foo.yaml']);
$this->setUpTest();
}
/**
* @test
*/
public function it_allows_to_get_collection_as_a_login_administrator_on_new_not_admin_resource(): void
{
$response = static::createClient()->request(
'GET',
'api/v2/foos',
['auth_bearer' => $this->JWTAdminUserToken]
);
$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->runAssertions($response, 0);
$this->runAssertions($response, 1);
}
/**
* @test
*/
public function it_allows_to_get_collection_as_a_visitor(): void
{
$response = static::createClient()->request('GET', 'api/v2/foos');
$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->runAssertions($response, 0);
$this->runAssertions($response, 1);
}
/**
* @test
*/
public function it_allows_to_get_item_by_iri(): void
{
/** @var Foo $foo */
$foo = $this->objects['foo1'];
$response = static::createClient()->request('GET', 'api/v2/foos/' . $foo->getId());
$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertSame(json_decode($response->getContent(), true)['name'], 'Foo0');
}
/**
* @test
*/
public function it_allows_to_post_as_a_visitor(): void
{
$fooSyliusResourceIri = $this->findIriBy(FooSyliusResource::class, ['name' => 'FooSyliusResource3']);
$adminIri = $this->findIriBy(AdminUser::class, ['username' => 'sylius']);
$response = static::createClient()->request(
'POST',
'api/v2/foos',
['json' =>
[
"name" => "FooPost",
"owner" => $adminIri,
"fooSyliusResource" => $fooSyliusResourceIri,
],
]
);
$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$object = json_decode($response->getContent(), true);
$this->assertSame('FooPost', $object['name']);
$this->assertTrue(str_contains($object['owner'], 'api/v2/admin/administrators'));
$this->assertTrue(str_contains($object['fooSyliusResource'], 'api/v2/foo-sylius-resource'));
}
private function runAssertions(ResponseInterface $response, int $objectNumber): void
{
$objects = json_decode($response->getContent(), true)['hydra:member'];
$object1 = $objects[$objectNumber];
$this->assertSame('Foo' . $objectNumber, $object1['name']);
$this->assertTrue(str_contains($object1['owner'], 'api/v2/admin/administrators'));
$this->assertTrue(str_contains($object1['fooSyliusResource'], 'api/v2/foo-sylius-resource'));
}
}

View file

@ -0,0 +1,59 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* 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\Bundle\ApiBundle\Application\Tests;
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
final class PromotionTest extends ApiTestCase
{
use SetUpTestsTrait;
public function setUp(): void
{
$this->setFixturesFiles(['test/config/fixtures/promotions.yaml']);
$this->setUpTest();
}
/**
* @test
*/
public function it_allows_to_get_collection_as_a_visitor_on_resource_from_api_bundle_with_customized_path(): void
{
$response = static::createClient()->request('GET', '/api/v2/custom/promotions');
$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$objects = json_decode($response->getContent(), true)['hydra:member'];
$this->assertSame('Sunday promotion', $objects[0]['name']);
}
/**
* @test
*/
public function it_allows_to_get_collection_as_an_login_administrator_on_resource_from_api_bundle_with_customized_path(): void
{
$response = static::createClient()->request(
'GET',
'/api/v2/custom/promotions',
['auth_bearer' => $this->JWTAdminUserToken]
);
$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$objects = json_decode($response->getContent(), true)['hydra:member'];
$this->assertSame('Sunday promotion', $objects[0]['name']);
}
}

View file

@ -0,0 +1,55 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\ApiBundle\Application\Tests;
use Fidry\AliceDataFixtures\LoaderInterface;
use Fidry\AliceDataFixtures\Persistence\PurgeMode;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
trait SetUpTestsTrait
{
/** @var string */
private $JWTAdminUserToken;
/** @var array */
private $fixturesFiles;
/** @var array */
private $objects;
public function setFixturesFiles(array $fixturesFiles)
{
$this->fixturesFiles = array_merge(
$fixturesFiles,
['test/config/fixtures/administrator.yaml', 'test/config/fixtures/channel.yaml']
);
}
public function setUpTest(): void
{
parent::setUp();
$kernel = self::bootKernel();
$container = $kernel->getContainer();
/** @var LoaderInterface $loader */
$loader = $container->get('fidry_alice_data_fixtures.loader.doctrine');
/** @var JWTTokenManagerInterface $JWTManager */
$JWTManager = $container->get('lexik_jwt_authentication.jwt_manager');
$this->objects = $loader->load($this->fixturesFiles, [], [], PurgeMode::createDeleteMode());
$adminUser = $this->objects['admin'];
$this->JWTAdminUserToken = $JWTManager->create($adminUser);
}
}

View file

@ -0,0 +1,42 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* 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\Bundle\ApiBundle\Application\Tests;
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
final class TaxonTest extends ApiTestCase
{
use SetUpTestsTrait;
public function setUp(): void
{
$this->setFixturesFiles(['test/config/fixtures/taxons.yaml']);
$this->setUpTest();
}
/**
* @test
*/
public function it_allows_to_get_collection_as_a_visitor(): void
{
$response = static::createClient()->request('GET', '/api/v2/shop/taxons');
$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$objects = json_decode($response->getContent(), true)['hydra:member'];
$this->assertSame('default', $objects[0]['type']);
}
}