Permalink
Browse files

Add behat tests (#21)

  • Loading branch information...
kunicmarko20 committed Aug 24, 2018
1 parent eb89633 commit 62f7a266f9de54615437ed8cbebe0ceaa5f01096
View
@@ -3,6 +3,7 @@
.yamllint export-ignore
.flintci.yml export-ignore
.travis.yml export-ignore
behat.yml export-ignore
phpcs.xml export-ignore
phpunit.xml.dist export-ignore
README.md export-ignore
@@ -12,3 +13,4 @@ Makefile export-ignore
/.travis/ export-ignore
/.github/ export-ignore
/tests/ export-ignore
/features/ export-ignore
View
@@ -1,5 +1,6 @@
language: php
sudo: true
php:
- '7.1'
- '7.2'
@@ -15,7 +16,11 @@ matrix:
- php: '7.1'
env: SYMFONY=3.4.*
- php: '7.1'
env: SYMFONY=4.0.*
env: SYMFONY=4.0.3
- php: '7.1'
env: SYMFONY=4.1.*
- php: '7.1'
env: TARGET=behat
allow_failures:
- php: nightly
View
@@ -0,0 +1,10 @@
#!/usr/bin/env sh
set -ev
sudo apt update
composer install --dev --prefer-dist
sudo apt install xvfb
sudo apt install firefox
wget https://selenium-release.storage.googleapis.com/3.14/selenium-server-standalone-3.14.0.jar
DISPLAY=:10 xvfb-run java -jar selenium-server-standalone-3.14.0.jar > /dev/null &
sleep 5
View
@@ -0,0 +1,8 @@
#!/usr/bin/env sh
set -ev
features/Fixtures/Project/bin/console --no-interaction cache:clear --env=test
features/Fixtures/Project/bin/console doctrine:schema:update --force --env=test
features/Fixtures/Project/bin/console assets:install
nohup php -S 127.0.0.1:8000 -t features/Fixtures/Project/public 2>&1 &
vendor/bin/behat
View
@@ -0,0 +1,17 @@
default:
suites:
default:
contexts:
- KunicMarko\SonataAnnotationBundle\Features\Context\AdminContext
extensions:
Behat\MinkExtension:
base_url: 'http://127.0.0.1:8000/'
goutte: ~
selenium2: ~
Behat\Symfony2Extension:
kernel:
env: test
debug: true
path: features/Fixtures/Project/src/Kernel.php
class: KunicMarko\SonataAnnotationBundle\Features\Fixtures\Project\Kernel
bootstrap: tests/bootstrap.php
View
@@ -30,7 +30,17 @@
"sonata-project/admin-bundle": "<3.35"
},
"require-dev": {
"behat/behat": "^3.5",
"behat/mink": "1.7.x-dev",
"behat/mink-browserkit-driver": "^1.3",
"behat/mink-extension": "^2.3",
"behat/mink-goutte-driver": "^1.2",
"behat/mink-selenium2-driver": "^1.3",
"behat/symfony2-extension": "^2.1",
"doctrine/doctrine-fixtures-bundle": "^3.0",
"matthiasnoback/symfony-dependency-injection-test": "^3.0",
"sonata-project/doctrine-orm-admin-bundle": "^3.6",
"symfony/framework-bundle": "^3.4 || ^4.0",
"symfony/phpunit-bridge": "^4.0"
},
"config": {
@@ -48,7 +58,9 @@
},
"autoload-dev": {
"psr-4": {
"KunicMarko\\SonataAnnotationBundle\\Tests\\": "tests/"
"KunicMarko\\SonataAnnotationBundle\\Tests\\": "tests/",
"KunicMarko\\SonataAnnotationBundle\\Features\\Fixtures\\Project\\": "features/Fixtures/Project/src",
"KunicMarko\\SonataAnnotationBundle\\Features\\": "features/"
}
}
}
@@ -0,0 +1,62 @@
<?php
namespace KunicMarko\SonataAnnotationBundle\Features\Context;
use Behat\MinkExtension\Context\MinkContext;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\ORM\EntityManagerInterface;
use Behat\Symfony2Extension\Context\KernelDictionary;
use KunicMarko\SonataAnnotationBundle\Features\Fixtures\CategoryFixtures;
use Doctrine\Common\DataFixtures\Loader;
class AdminContext extends MinkContext
{
use KernelDictionary;
/**
* @BeforeScenario
*/
public function clearData()
{
$this->getPurger()->purge();
}
private function getPurger()
{
return new ORMPurger($this->getEntityManager());
}
private function getEntityManager(): EntityManagerInterface
{
return $this->getContainer()->get('doctrine.orm.entity_manager');
}
/**
* @Given I am on the dashboard
*/
public function iAmOnTheDashboard()
{
$this->visitPath('/admin/dashboard');
}
/**
* @Given I have items in the database
*/
public function iHaveItemsInTheDatabase()
{
$loader = new Loader();
$loader->addFixture(new CategoryFixtures());
$executor = new ORMExecutor($this->getEntityManager(), $this->getPurger());
$executor->execute($loader->getFixtures());
}
/**
* @Then I should see :button button
*/
public function iShouldSeeAButton($button)
{
$this->getSession()->getPage()->find('xpath', "//a[contains(text(), $button)]");
}
}
@@ -0,0 +1,18 @@
<?php
namespace KunicMarko\SonataAnnotationBundle\Features\Fixtures;
use KunicMarko\SonataAnnotationBundle\Features\Fixtures\Project\Entity\Category;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
class CategoryFixtures extends Fixture
{
public function load(ObjectManager $manager)
{
$category = new Category('Dummy Category');
$manager->persist($category);
$manager->flush();
}
}
@@ -0,0 +1,10 @@
###> symfony/framework-bundle ###
/.env
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###
###> symfony/web-server-bundle ###
/.web-server-pid
###< symfony/web-server-bundle ###
@@ -0,0 +1,17 @@
#!/usr/bin/env php
<?php
use KunicMarko\SonataAnnotationBundle\Features\Fixtures\Project\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
set_time_limit(0);
require __DIR__.'../../../../../vendor/autoload.php';
umask(0000);
$input = new ArgvInput();
$kernel = new Kernel('test', true);
$application = new Application($kernel);
$application->run($input);
@@ -0,0 +1,17 @@
<?php
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true],
Sonata\DatagridBundle\SonataDatagridBundle::class => ['all' => true],
Sonata\CoreBundle\SonataCoreBundle::class => ['all' => true],
Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true],
Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true],
Sonata\AdminBundle\SonataAdminBundle::class => ['all' => true],
Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle::class => ['all' => true],
KunicMarko\SonataAnnotationBundle\SonataAnnotationBundle::class => ['all' => true],
];
@@ -0,0 +1,21 @@
doctrine:
dbal:
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: 'sqlite:///%kernel.project_dir%/var/cache/app.db'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
SonataAnnotationBundle:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'KunicMarko\SonataAnnotationBundle\Features\Fixtures\Project\Entity'
alias: SonataAnnotationBundle
@@ -0,0 +1,7 @@
framework:
secret: '%env(APP_SECRET)%'
test: true
session:
storage_id: session.storage.mock_file
php_errors:
log: true
@@ -0,0 +1,3 @@
framework:
router:
strict_requirements: ~
@@ -0,0 +1,9 @@
security:
providers:
in_memory: {memory: ~}
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: true
@@ -0,0 +1,10 @@
sonata_admin:
title: 'Sonata Admin'
dashboard:
blocks:
- {type: sonata.admin.block.admin_list, position: left}
sonata_block:
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
@@ -0,0 +1,4 @@
sonata_core:
form:
mapping:
enabled: false
@@ -0,0 +1,3 @@
twig:
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
@@ -0,0 +1,8 @@
admin_area:
resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
prefix: /admin
_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin
@@ -0,0 +1,11 @@
parameters:
locale: 'en'
services:
_defaults:
autowire: true
autoconfigure: true
public: false
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
@@ -0,0 +1,14 @@
<?php
use KunicMarko\SonataAnnotationBundle\Features\Fixtures\Project\Kernel;
use Symfony\Component\HttpFoundation\Request;
require __DIR__.'../../../../../vendor/autoload.php';
umask(0000);
$kernel = new Kernel('test', true);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
@@ -0,0 +1,54 @@
<?php
namespace KunicMarko\SonataAnnotationBundle\Features\Fixtures\Project\Entity;
use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;
/**
* @Sonata\Admin("Category")
*
* @Sonata\ListAction("edit")
* @Sonata\ListAction("delete")
*
* @ORM\Entity
*/
class Category
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
public $id;
/**
* @Sonata\FormField()
* @Sonata\ListField()
* @Sonata\ShowField()
* @Sonata\DatagridField()
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
public function __construct(string $name = null)
{
$this->name = $name;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): void
{
$this->name = $name;
}
}
Oops, something went wrong.

0 comments on commit 62f7a26

Please sign in to comment.