Code Monkey home page Code Monkey logo

pluginskeleton's Introduction

Sylius Logo.

Plugin Skeleton

Skeleton for starting Sylius plugins.

Documentation

For a comprehensive guide on Sylius Plugins development please go to Sylius documentation, there you will find the Plugin Development Guide, that is full of examples.

Quickstart Installation

Traditional

  1. Run composer create-project sylius/plugin-skeleton ProjectName.

  2. From the plugin skeleton root directory, run the following commands:

    $ (cd tests/Application && yarn install)
    $ (cd tests/Application && yarn build)
    $ (cd tests/Application && APP_ENV=test bin/console assets:install public)
    
    $ (cd tests/Application && APP_ENV=test bin/console doctrine:database:create)
    $ (cd tests/Application && APP_ENV=test bin/console doctrine:schema:create)

To be able to set up a plugin's database, remember to configure you database credentials in tests/Application/.env and tests/Application/.env.test.

Docker

  1. Execute docker compose up -d

  2. Initialize plugin docker compose exec app make init

  3. See your browser open localhost

Usage

Running plugin tests

  • PHPUnit

    vendor/bin/phpunit
  • PHPSpec

    vendor/bin/phpspec run
  • Behat (non-JS scenarios)

    vendor/bin/behat --strict --tags="~@javascript"
  • Behat (JS scenarios)

    1. Install Symfony CLI command.

    2. Start Headless Chrome:

    google-chrome-stable --enable-automation --disable-background-networking --no-default-browser-check --no-first-run --disable-popup-blocking --disable-default-apps --allow-insecure-localhost --disable-translate --disable-extensions --no-sandbox --enable-features=Metal --headless --remote-debugging-port=9222 --window-size=2880,1800 --proxy-server='direct://' --proxy-bypass-list='*' http://127.0.0.1
    1. Install SSL certificates (only once needed) and run test application's webserver on 127.0.0.1:8080:
    symfony server:ca:install
    APP_ENV=test symfony server:start --port=8080 --dir=tests/Application/public --daemon
    1. Run Behat:
    vendor/bin/behat --strict --tags="@javascript"
  • Static Analysis

    • Psalm

      vendor/bin/psalm
    • PHPStan

      vendor/bin/phpstan analyse -c phpstan.neon -l max src/  
  • Coding Standard

    vendor/bin/ecs check

Opening Sylius with your plugin

  • Using test environment:

    (cd tests/Application && APP_ENV=test bin/console sylius:fixtures:load)
    (cd tests/Application && APP_ENV=test bin/console server:run -d public)
  • Using dev environment:

    (cd tests/Application && APP_ENV=dev bin/console sylius:fixtures:load)
    (cd tests/Application && APP_ENV=dev bin/console server:run -d public)

pluginskeleton's People

Contributors

bartoszpietrzak1994 avatar bitbager avatar codermaggie avatar coldic3 avatar damonsson avatar dependabot-preview[bot] avatar dependabot[bot] avatar ferror avatar gsadee avatar jakubtobiasz avatar jibbarth avatar kmatulewicz avatar lamasfoker avatar lchrusciel avatar loevgaard avatar lsmith77 avatar mamazu avatar marek-pietrzak-tg avatar mmenozzi avatar nedac-sorbo avatar noresponsemate avatar oallain avatar pamil avatar pjedrzejewski avatar prometee avatar radnok avatar rafikooo avatar stefandoorn avatar vvasiloi avatar zales0123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pluginskeleton's Issues

Use the .env file everywhere (and not the .env.test)

Hi guys,
I think that we should use the .env file inside tests/Application as the only .env file used both for CI and for development.

Currently, if we want to use .env files, to make the plugin work locally we need to copy .env.test.dist to .env.test and to .env (we don't want to do set -a && source tests/Application/.env.test && set +a locally). Then in the .env file we can do our changes (for example use a SQLite DB).

I propose to change the following line:

env_file: tests/Application/.env.test

to:

env_file: tests/Application/.env

It this way we can remove set -a && source tests/Application/.env.test && set +a from the .travis.yml file and then also remove all the -e test from all the commands in the README.

What do you think?

Readme leads to errors

After cloning this repo I went to the tests/Appliation folder and followed the instruction in the README. Therefore I did

  • yarn install -> works fine
  • yarn build -> errors:
yarn run v1.10.1
$ gulp build
[12:53:17] Failed to load external module @babel/register
[12:53:17] Requiring external module babel-register
[12:53:18] Using gulpfile ~/Development/Sylius/PluginSkeleton/tests/Application/gulpfile.babel.js
[12:53:18] Starting 'build'...
[12:53:18] Starting 'buildAdmin'...
[12:53:18] Starting 'buildShop'...
[12:53:18] 'buildAdmin' errored after 19 ms
[12:53:18] Error: File not found with singular glob: /Users/sok/Development/Sylius/PluginSkeleton/tests/Application/../../vendor/sylius/sylius/src/Sylius/Bundle/AdminBundle/gulpfile.babel.js (if this was purposeful, use `allowEmpty` option)
    at Glob.<anonymous> (/Users/sok/Development/Sylius/PluginSkeleton/tests/Application/node_modules/glob-stream/readable.js:84:17)
    at Object.onceWrapper (events.js:273:13)
    at Glob.emit (events.js:182:13)
    at Glob.EventEmitter.emit (domain.js:442:20)
    at Glob._finish (/Users/sok/Development/Sylius/PluginSkeleton/tests/Application/node_modules/glob/glob.js:197:8)
    at done (/Users/sok/Development/Sylius/PluginSkeleton/tests/Application/node_modules/glob/glob.js:182:14)
    at Glob._processSimple2 (/Users/sok/Development/Sylius/PluginSkeleton/tests/Application/node_modules/glob/glob.js:688:12)
    at /Users/sok/Development/Sylius/PluginSkeleton/tests/Application/node_modules/glob/glob.js:676:10
    at Glob._stat2 (/Users/sok/Development/Sylius/PluginSkeleton/tests/Application/node_modules/glob/glob.js:772:12)
    at lstatcb_ (/Users/sok/Development/Sylius/PluginSkeleton/tests/Application/node_modules/glob/glob.js:764:12)
[12:53:18] 'build' errored after 26 ms
[12:53:18] The following tasks did not complete: buildShop
[12:53:18] Did you forget to signal async completion?
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Testing plugin at end user - Behat

Let's assume I am working on SyliusWalletPlugin which extends user to have wallet feature as follows

In my plugin, I have defined interface and walletableTrait

UserWalletInterface extends UserInterface
{
  public function getWallet();
}

Now the end user who uses the plugin needs to implement UserWalletInterface and include wallatable trait.

Now how one can do Behat scenario testing which doesn't have a working User class which can only be implemented at the end user.

Move db.sql to another location

Currently, the db.sql file is placed in var/cache directory which makes clearing the cache tricky. Moving it to var/db location should fix this issue.

Use different database for different environments

Currently, the db.sql file is shared between dev and test environment. Sometimes it's a little bit annoying as Behat Doctrine hook context clears the database the developer could have filled with some dev data.

yarn run gulp - Problem finding locally-installed `gulp`

After running yarn install, is unable to run successfully yarn run gulp, which output is:

\tests\Application> yarn run gulp
yarn run v0.22.0
$ gulp
[14:31:24] Using gulpfile C:\Coding\php\SyliusMyPlugin\tests\Application\gulpfile.js
[14:31:24] Starting 'admin'...
[14:31:24] Finished 'admin' after 11 ms
[14:31:24] Starting 'shop'...
[14:31:24] Finished 'shop' after 3.82 ms
[14:31:24] Starting 'default'...
[14:31:24] Finished 'default' after 41 μs
[gulp-chug] Gulpfile, Gulpfile.js, contents is empty. Reading directly from disk...

events.js:160
      throw er; // Unhandled 'error' event
      ^
Error: Problem finding locally-installed `gulp` for gulpfile �[35mundefined�[39m. (Try running `npm install gulp` from �[35mC:\Coding\php\SyliusMyPlugin\vendor\sylius\sylius\src\Sylius\Bundle\AdminBundle�[39m to install a local gulp for said gulpfile.)

Error: Cannot find module 'gulp' from 'C:\Coding\php\SyliusMyPlugin\vendor\sylius\sylius\src\Sylius\Bundle\AdminBundle'
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Also tried to run npm install gulp, which also installed globally, but it not helped. Windows 10 x64

"Channel could not be found!"

As soon as I'm trying to use the channel context anywhere and do XML / API testing on it (PHPUnit) I get the error that the Channel could not be found. I'm using the default fixtures and the skeleton application.

Is there a way I can set the single channel available in the fixtures as the one being used before I run the tests?

Allow Model namespace

Hi there!

Would it be possible to customize the SyliusPluginTrait so that it accepts Model namespace instead of Entity for Doctrine declarations?

NelmioAliceBundle not found when trying to install assets

When trying to install the plugin skeleton we get an error from the Nelmio Alice bundle.

Command:
(cd tests/Application && bin/console assets:install web -e test)

Error:

PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "NelmioAliceBundle" from namespace "Nelmio\Alice\Bridge\Symfony".
Did you forget a "use" statement for another namespace? in /Users/*/projects/syliusplugin/vendor/sylius/sylius/src/Sylius/Bundle/CoreBundle/Application/Kernel.php:103

Plugin install/uninstall

It's a common use case to install/uninstall plugins for any e-commerce plateforme.

If I create a plugin which require to extend the DB schema by new columns/tables, how can I tell my customers to install this plugin: there should be simple and unique procedure to apply on all Sylius plugins.

I don't think I should ask them to exec app/console doctrine:schema:update --force

Same question: how can I guide them to uninstall it?

Magento2 for example, offers a command to enable/disable + install/uninstall plugins.
Also it gives plugin developers a clear interface to write install/uninstall scripts (similar to doctrine migrations)

Context "I am logged in as an administrator" failing

After installing a new project, and launching all the commands, then running the behat tests with Selenium, the context "I am logged in as an administrator" doesn't seem to be working.

I can see that a user is created in the database, but I am not logged in : the 3 example scenarios accessing the admin part of the website are failing because I am redirected to the login page.

Expected to be on "http://localhost:8080/admin/products/new/simple" but found "http://localhost:8080/admin/login" instead (Sylius\Behat\Page\UnexpectedPageException)

Is there a configuration that I am missing somewhere ? For the sessions ? The cache ? Something else ? The weird thing is that if I launch the website on http://localhost:8080, I can log in, and go to the given pages without problem.

FatalThrowableError @ http://localhost:8000/dynamic-welcome

Hi, I tried latest skeleton setup and followed all given instruction. When I tried dynamic route :
http://localhost:8000/dynamic-welcome
or http://localhost:8000/dynamic-welcome/waqar
I got following exception:
(1/1) FatalThrowableError Type error: Argument 1 passed to FOS\RestBundle\Controller\ExceptionController::__construct() must be an instance of FOS\RestBundle\View\ViewHandlerInterface, none given, called in /home/waqar/mydev/salesperson/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php on line 202

 Please guide for this.

Missing mink parameters

Hi, I tried a Plugin Skeleton, but behat tests failed for default features:

@managing_products
Feature: Adding a new product with text attribute
    In order to extend my merchandise with more complex products
    As an Administrator
    I want to add a new product with text attribute to the shop

  Background:
    Given the store operates on a single channel in "United States"
    And the store has a text product attribute "Gun caliber"
    And the store has a text product attribute "Overall length"
    And I am logged in as an administrator
      Type error: strpos() expects parameter 1 to be string, null given (Behat\Testwork\Call\Exception\FatalThrowableError)
      #1 vendor/sylius/sylius/src/Sylius/Behat/Service/Setter/CookieSetter.php(50): Sylius\Behat\Service\Setter\CookieSetter->prepareMinkSessionIfNeeded()
      #2 vendor/sylius/sylius/src/Sylius/Behat/Service/SecurityService.php(103): Sylius\Behat\Service\Setter\CookieSetter->setCookie('MOCKSESSID', 'bf43018f907a5ca...')
      #3 vendor/sylius/sylius/src/Sylius/Behat/Service/SecurityService.php(62): Sylius\Behat\Service\SecurityService->setToken(Object(Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken))
      #4 vendor/sylius/sylius/src/Sylius/Behat/Context/Setup/AdminSecurityContext.php(74): Sylius\Behat\Service\SecurityService->logIn(Object(Sylius\Component\Core\Model\AdminUser))
      #5 [internal function]: Sylius\Behat\Context\Setup\AdminSecurityContext->iAmLoggedInAsAnAdministrator()

Can you advice what is the configuration which will make this work, please?
Would be great if the documentation mentioned that.

Command not found: bin/console

The README mentioned to execute the bin/console command to install the assets. However the command was not found because it is not executable by default. Add chmod +x bin/console to the README file.

JS Behat tests failing due to session or auth issue (selenium & chromedriver)

Hi, guys.

It looks like JS behat tests failing due to some session or auth issue:

$ vendor/bin/behat 
@managing_products
...
  @ui @javascript
  Scenario: Adding a text attribute to product
    Given I want to create a new simple product
      Expected to be on "http://localhost:8080/admin/products/new/simple" but found "http://localhost:8080/admin/login" instead (Sylius\Behat\Page\UnexpectedPageException)

PS: I've followed all installation steps for clean copy of latest plugin skeleton. Chromedriver and selenium server also latest.

Also, how about adding it to travis and add badges? As I can see - config is ready for that.
Thanks

Cache and logs dir

Why cache and logs directories are being set to the system's root /tmp instead of project /var? Can I set it to default path or will it cause some unexpected problems?

Twig_Error_Runtime > Channel could not be found! on my first server:run

Hello, I'm not able to run the skeleton. when I do:
php bin/console server:run --env=dev --docroot=/path/to/MyPlug/tests/Application/web
I got error:
**
ChannelNotFoundException Twig_Error_Runtime
HTTP 500 Internal Server Error

An exception has been thrown during the rendering of a template ("Channel could not be found! Tip: You can use the Web Debug Toolbar to switch between channels in development.").**

Add app.php front controller

Because the SyliusPluginSkeleton is just a Symfony app, some more advanced plugins can be presented as the demo app. That being said, in this case, it'd require a front controller for prod environment.

Database credentials / Admin user credentials

I would add somewhere in the README that to be able to launch the database commands, you have to modify the .env files in tests/Application with your database credentials.

Also, I had to search in the database if there was any admin users created, and by chance the password is the same as the username, so I would also add in the readme that you can access the admin panel with the username sylius and the password sylius.

Do not require unnecessary dependencies

By including Sylius' behat.yml.dist we require dependencies that are not necessary, but can not be disabled:

  • behat/mink-selenium2-driver
  • friends-of-behat/performance-extension
  • friends-of-behat/variadic-extension
  • lakion/mink-debug-extension

Newer Yarn version

Currently yarn=0.21.3-1 is being used. Is there anything preventing using the latest Yarn version in Travis CI?

Less strict about Sylius version

Current installation requires "sylius/sylius": "~1.4.0@dev",. Can't that just be that latest supported Sylius version? In that case plugin developers take a wider range of Sylius versions in mind (also should maybe be tested against in Travis), and not only using latest versions. Makes plugins available to a bigger group of developers.

Enable dev environment

It would be nice to have dev environment near to test one. Even though BDD is great, sometimes running an app on separate database makes life easier, for example when a dev wants to write some dummy code before deciding if the whole feature should be implemented in a specific way.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.