cuteninja / parabola-bundle
Common code handling API for Cute-Ninja projects (ResponseBuilder, Testing, ...)
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 1 719
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Type:symfony-bundle
Requires
- php: >=5.5.9
- friendsofsymfony/rest-bundle: ~1.4
- incenteev/composer-parameter-handler: ~2.0
- knplabs/knp-paginator-bundle: ~2.4
- sensio/distribution-bundle: ~3.0|~4.0|~5.0
- sensio/framework-extra-bundle: ~3.0
- symfony/monolog-bundle: ~2.4
- symfony/symfony: 2.6.*|2.8.*
Requires (Dev)
- behat/symfony2-extension: 2.1.*
- phpunit/phpunit: 4.8.*
- sensio/generator-bundle: ~2.3
This package is not auto-updated.
Last update: 2024-09-28 18:58:37 UTC
README
This bundle provide tools to handle Rest API. It includes response builders (Success, ServerError, Client Error) and functionnal testing (using Behat).
Configuration
To be able to use "the response must be optimized" you need to enable the profiler in config_test.yml
profiler: enabled: true
and enable debug when instantiating the kernel
new \AppKernel('test', true);
And in your paramaters.yml define cute_ninja_parabola_allowed_origins with the url of your API. The parameter is an array to allow you to have multi sources allowed.
For exemple:
cute_ninja_parabola_allowed_origins: - 'http://api.my-application.com'
To enable API wrapping and access the display of the symfony2 profilter, add the following to your parameters.yml
wrap_api_response: true
BaseContext
Create a BaseContext in your project has follow
use CuteNinja\ParabolaBundle\Tests\Feature\Context\BaseContext as ParabolaBaseContext; class BaseContext extends ParabolaBaseContext { }
DB structure & Data
The functionnal tests require you to generate DB structure and populate it with data. The best way to do it is by implementing two methods with the annotations "@BeforeSuite" and " @AfterScenario @regenerateDB". To optimize the DB loading we generate the before each suite and after a scenario that use the "@regenerateDB". This way we won't reload the DB after a test on List API for example since the DB conttent hasn't been modify.
use CuteNinja\ParabolaBundle\Tests\Feature\Context\BaseContext as ParabolaBaseContext; class BaseContext extends ParabolaBaseContext { /** * @BeforeSuite */ public static function beforeSuite() { // Implement your own DB structure and data logic } /** * @AfterScenario @regenerateDB */ public function regenerateDBAfterScenario() { // Implement your own DB structure and data logic } }
If you want, you can use https://github.com/Cute-Ninja/memoria-bundle to handle the DB structure and data by adding it to your project and using the following code.
use CuteNinja\ParabolaBundle\Tests\Feature\Context\BaseContext as ParabolaBaseContext; class BaseContext extends ParabolaBaseContext { /** * @BeforeSuite */ public static function beforeSuite() { $process = new Process("php bin/console doctrine:schema:create --env=test"); $process->setTimeout(3600); $process->run(); $process = new Process("php bin/console cute_ninja:fixture:load --env=test"); $process->setTimeout(3600); $process->run(); } /** * @AfterScenario @regenerateDB */ public function regenerateDBAfterScenario() { $process = new Process("php bin/console doctrine:schema:drop --force --env=test"); $process->setTimeout(3600); $process->run(); $process = new Process("php bin/console doctrine:schema:create --env=test"); $process->setTimeout(3600); $process->run(); $process = new Process("php bin/console cute_ninja:fixture:load --env=test"); $process->setTimeout(3600); $process->run(); } }