Skip to content

Commit

Permalink
Fix Behat for CI (#1682)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored Oct 16, 2021
1 parent 2c546eb commit 904939a
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 74 deletions.
25 changes: 10 additions & 15 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
- name: Check Coding Style (only for CodingStyle)
if: matrix.type == 'CodingStyle'
run: |
if [ "$(find demos/ -name '*.php' -print0 | xargs -0 grep -L "namespace Atk4\\\\Ui\\\\Demos;" | tee /dev/fd/2)" ]; then echo 'All demos/ files must have namespace declared' && (exit 1); fi
if [ "$(find demos/ -name '*.php' -print0 | xargs -0 grep -L "namespace Atk4\\\\Ui\\\\Demos[;\\\\]" | tee /dev/fd/2)" ]; then echo 'All demos/ files must have namespace declared' && (exit 1); fi
vendor/bin/php-cs-fixer fix --dry-run --using-cache=no --diff --verbose
- name: Run Static Analysis (only for StaticAnalysis)
Expand Down Expand Up @@ -219,7 +219,7 @@ jobs:
name: Behat
runs-on: ubuntu-latest
container:
image: ghcr.io/mvorisek/image-php:${{ matrix.php }}-node
image: ghcr.io/mvorisek/image-php:${{ matrix.php }}-selenium
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -255,12 +255,6 @@ jobs:
image: ghcr.io/mvorisek/docker-oracle-xe-11g
env:
ORACLE_ALLOW_REMOTE: true
selenium-chrome:
image: selenium/standalone-chrome:latest
options: --health-cmd "/opt/bin/check-grid.sh"
selenium-firefox:
image: selenium/standalone-firefox:latest
options: --health-cmd "/opt/bin/check-grid.sh"
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -339,16 +333,17 @@ jobs:
if [ -n "$LOG_COVERAGE" ]; then mkdir coverage && cp tools/CoverageUtil.php demos; fi
sed -E "s/\(('sqlite:.+)\);/(\$_ENV['DB_DSN'] ?? \\1, \$_ENV['DB_USER'] ?? null, \$_ENV['DB_PASSWORD'] ?? null);/g" -i demos/db.default.php
sed -i "s~'https://raw.githack.com/atk4/ui/develop/public.*~'/public',~" src/App.php
php -S 172.18.0.2:8888 > /dev/null 2>&1 &
sleep 0.2
ci_wait_until () { timeout 30 sh -c "until { $1 2> /dev/null; }; do sleep 0.02; done" || timeout 15 sh -c "$1" || { echo "health timeout: $1"; exit 1; }; }
php -S 127.0.0.1:8888 > /dev/null 2>&1 &
ci_wait_until 'nc -w 1 127.0.0.1 8888'
if [ -f /etc/alpine-release ]; then addgroup browser && adduser browser -G browser -D -s /bin/sh; else adduser browser --gecos "" --disabled-login -shell /bin/sh > /dev/null; fi
{ Xvfb -ac :99 -screen 0 1920x1200x24 2> /dev/null & } && export DISPLAY=:99
ci_wait_until '[ -e /tmp/.X11-unix/X99 ]'
su browser -c 'java -Dwebdriver.chrome.whitelistedIps=127.0.0.1 -jar /opt/selenium-server-standalone.jar -role standalone -host 127.0.0.1 -port 4444 -sessionTimeout 15 -browserTimeout 12 > /dev/null 2>&1 &'
ci_wait_until 'nc -w 1 127.0.0.1 4444'
if [ "${{ matrix.type }}" == "Firefox" ]; then sed -i "s~chrome~firefox~" behat.yml.dist; fi
if [ "${{ matrix.type }}" == "Chrome Slow" ]; then echo 'sleep(1);' >> demos/init-app.php; fi
# remove once https://github.com/minkphp/Mink/pull/801
# and https://github.com/minkphp/MinkSelenium2Driver/pull/322 are released
sed -i 's/usleep(100000)/usleep(5000)/' vendor/behat/mink/src/Element/Element.php
sed -i 's/usleep(100000)/usleep(5000)/' vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php
- name: "Run tests: SQLite"
run: |
php demos/_demo-data/create-db.php
Expand Down
11 changes: 7 additions & 4 deletions behat.yml.dist
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
default:
suites:
atk4_ui:
main:
paths:
features: '%paths.base%/tests-behat'
contexts:
- Behat\MinkExtension\Context\MinkContext
- Atk4\Ui\Behat\Context
extensions:
Behat\MinkExtension:
base_url: 'http://172.18.0.2:8888/demos'
base_url: 'http://127.0.0.1:8888/demos'
sessions:
default:
selenium2:
browser: chrome
wd_host: 'http://selenium-chrome:4444/wd/hub'
wd_host: 'http://127.0.0.1:4444/wd/hub'
capabilities:
extra_capabilities:
chrome:
args:
- '--no-sandbox'
- '--headless'
- '--window-size=1930,1200'
- '--disable-dev-shm-usage'
- '--disable-gpu'
- '--window-size=1920,1200'
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
},
"require-dev": {
"behat/behat": "^3.8.2 || dev-master#6f38d11",
"behat/gherkin": "^4.8.1 || dev-master#5fbf806",
"behat/mink": "^1.8.2 || dev-master#1ab79d6",
"behat/gherkin": "^4.9",
"behat/mink": "^1.9",
"behat/mink-extension": "^2.3.1",
"behat/mink-selenium2-driver": "^1.4",
"behat/mink-selenium2-driver": "^1.5",
"ergebnis/composer-normalize": "^2.13",
"friendsofphp/php-cs-fixer": "^3.0",
"fzaninotto/faker": "^1.6",
Expand Down
2 changes: 1 addition & 1 deletion demos/_unit-test/callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
$form->setModel($m->tryLoadAny(), [$m->fieldName()->name]);
$form->getControl($m->fieldName()->name)->caption = 'TestName';

$table = $app->add(new \Atk4\Ui\Table());
$table = \Atk4\Ui\Table::addTo($app);
$table->setModel($m);

$button = Button::addTo($app, ['First', ['ui' => 'atk-test']]);
Expand Down
4 changes: 2 additions & 2 deletions demos/data-action/jsactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
// Card component.
$card = \Atk4\Ui\Card::addTo($app);
$content = new \Atk4\Ui\View(['class' => ['content']]);
$content->add($img = new \Atk4\Ui\Image(['../images/kristy.png']));
$img = \Atk4\Ui\Image::addTo($content, ['../images/kristy.png']);
$img->addClass('right floated mini ui image');
$content->add(new \Atk4\Ui\Header(['Kristy']));
\Atk4\Ui\Header::addTo($content, ['Kristy']);

$card->addContent($content);
$card->addDescription('Kristy is a friend of Mully.');
Expand Down
4 changes: 2 additions & 2 deletions demos/interactive/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@

$card = \Atk4\Ui\Card::addTo($app);
$content = new \Atk4\Ui\View(['class' => ['content']]);
$content->add($img = new \Atk4\Ui\Image(['../images/kristy.png']));
$img = \Atk4\Ui\Image::addTo($content, ['../images/kristy.png']);
$img->addClass('right floated mini ui image');
$content->add($header = new \Atk4\Ui\Header(['Kristy']));
$header = \Atk4\Ui\Header::addTo($content, ['Kristy']);

$card->addContent($content);
$card->addDescription('Friend of Bob');
Expand Down
18 changes: 9 additions & 9 deletions demos/tutorial/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
EOF
);

$page->add(new Demo())->setCodeAndCall(function (View $owner) {
Demo::addTo($page)->setCodeAndCall(function (View $owner) {
$country = new \Atk4\Ui\Demos\CountryLock($owner->getApp()->db);

$country->addUserAction('send_message');
Expand All @@ -59,7 +59,7 @@
EOF
);

$page->add(new Demo())->setCodeAndCall(function (View $owner) {
Demo::addTo($page)->setCodeAndCall(function (View $owner) {
$country = new \Atk4\Ui\Demos\CountryLock($owner->getApp()->db);

$country->addUserAction('send_message', function () {
Expand All @@ -83,7 +83,7 @@
EOF
);

$page->add(new Demo())->setCodeAndCall(function (View $owner) {
Demo::addTo($page)->setCodeAndCall(function (View $owner) {
$country = new \Atk4\Ui\Demos\CountryLock($owner->getApp()->db);
$country = $country->loadAny();

Expand All @@ -99,7 +99,7 @@
EOF
);

$page->add(new Demo())->setCodeAndCall(function (View $owner) {
Demo::addTo($page)->setCodeAndCall(function (View $owner) {
$country = new \Atk4\Ui\Demos\CountryLock($owner->getApp()->db);
$country = $country->loadAny();

Expand All @@ -119,7 +119,7 @@
EOF
);

$page->add(new Demo())->setCodeAndCall(function (View $owner) {
Demo::addTo($page)->setCodeAndCall(function (View $owner) {
$model = new \Atk4\Data\Model($owner->getApp()->db, ['table' => 'test']);

$model->addUserAction('greet', [
Expand Down Expand Up @@ -147,9 +147,9 @@
},
]);

$owner->add(new \Atk4\Ui\Form\Control\Line([
\Atk4\Ui\Form\Control\Line::addTo($owner, [
'action' => $model->getUserAction('greet'),
]));
]);

\Atk4\Ui\View::addTo($owner, ['ui' => 'divider']);

Expand All @@ -160,7 +160,7 @@

/*
$wizard->addStep('More Ways', function ($page) {
$page->add(new Demo(['left_width' => 5, 'right_width' => 11]))->setCodeAndCall(function (View $owner) {
Demo::addTo($page, ['left_width' => 5, 'right_width' => 11])->setCodeAndCall(function (View $owner) {
$model = new Stat($owner->getApp()->db);
$model->addUserAction('mail', [
'fields' => ['currency_field'],
Expand All @@ -187,7 +187,7 @@ functionality and more. Next example shows how you can disable user action (add)
EOF
);

$page->add(new Demo())->setCodeAndCall(function (View $owner) {
Demo::addTo($page)->setCodeAndCall(function (View $owner) {
$country = new \Atk4\Ui\Demos\CountryLock($owner->getApp()->db);
$country->getUserAction('add')->enabled = false;
$country->getUserAction('delete')->enabled = function (Country $m) { return $m->id % 2 === 0; };
Expand Down
2 changes: 1 addition & 1 deletion docs/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ decorators defined at ``\Atk4\Ui\Form::Control``. See dedicated documentation fo

To tweak the UI properties of an form control input use ``setInputAttr()`` (and not the surrounding <div> as ``setAttr()`` would do). Here is how to set the HTML "maxlength" attribute on the generated input field::

$form = $this->add(new \Atk4\Ui\Form);
$form = \Atk4\Ui\Form::addTo($this);
$form->setModel($model);
$form->getControl('name')->setInputAttr('maxlength', 20);

Expand Down
30 changes: 3 additions & 27 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ parameters:
-
path: 'demos/_includes/Demo.php'
message: '~^Call to an undefined method Atk4\\Ui\\JsChain::initHighlighting\(\)\.$~'
-
path: 'demos/_unit-test/callback.php'
message: '~^Call to an undefined method Atk4\\Ui\\AbstractView::setModel\(\)\.$~'
-
path: 'demos/_unit-test/callback.php'
message: '~^Call to an undefined method Atk4\\Ui\\AbstractView::jsReload\(\)\.$~'
-
path: 'demos/collection/tablefilter.php'
message: '~^Call to an undefined method Atk4\\Ui\\Demos\\CountryLock::expr\(\)\.$~'
Expand Down Expand Up @@ -144,6 +138,9 @@ parameters:
-
path: 'src/CallbackLater.php'
message: '~^Method Atk4\\Ui\\CallbackLater::set\(\) should return mixed but return statement is missing\.$~'
-
path: 'src/Card.php'
message: '~^Call to an undefined method Atk4\\Ui\\AbstractView::setAction\(\)\.$~'
-
path: 'src/Card.php'
message: '~^Call to an undefined method Atk4\\Ui\\View::addFields\(\)\.$~'
Expand Down Expand Up @@ -321,9 +318,6 @@ parameters:
-
path: 'src/Card.php'
message: '~^Method Atk4\\Ui\\Card::addButton\(\) should return Atk4\\Ui\\View\|null but returns Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/CardDeck.php'
message: '~^Property Atk4\\Ui\\CardDeck::\$card \(Atk4\\Ui\\View\|string\) does not accept default value of type array\<int, string\>\.$~'
-
path: 'src/CardDeck.php'
message: '~^Property Atk4\\Ui\\CardDeck::\$container \(Atk4\\Ui\\View\|null\) does not accept default value of type array\<int\|string, class-string\|string\>\.$~'
Expand Down Expand Up @@ -366,9 +360,6 @@ parameters:
-
path: 'src/Crud.php'
message: '~^Parameter \#2 \$fields \(array\|null\) of method Atk4\\Ui\\Crud::setModel\(\) should be contravariant with parameter \$columns \(array\|bool\) of method Atk4\\Ui\\Grid::setModel\(\)$~'
-
path: 'src/Form.php'
message: '~^Property Atk4\\Ui\\Form::\$cb \(Atk4\\Ui\\Callback\) does not accept Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/Form.php'
message: '~^Property Atk4\\Ui\\Form::\$layout \(Atk4\\Ui\\Form\\Layout\) does not accept array\<int, string\>\.$~'
Expand Down Expand Up @@ -525,9 +516,6 @@ parameters:
-
path: 'src/View.php'
message: '~^Method Atk4\\Ui\\View::getClosestOwner\(\) should return Atk4\\Ui\\View\|null but empty return statement found\.$~'
-
path: 'src/VirtualPage.php'
message: '~^Property Atk4\\Ui\\VirtualPage::\$cb \(Atk4\\Ui\\Callback\) does not accept Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/VirtualPage.php'
message: '~^Parameter \#1 \$fx \(Closure\) of method Atk4\\Ui\\VirtualPage::set\(\) should be contravariant with parameter \$arg1 \(mixed\) of method Atk4\\Ui\\View::set\(\)$~'
Expand Down Expand Up @@ -840,9 +828,6 @@ parameters:
-
path: 'src/Card.php'
message: '~^Parameter \#2 \$selector of method Atk4\\Ui\\View::on\(\) expects Atk4\\Ui\\JsExpressionable\|string\|null, Atk4\\Data\\Model\\UserAction given\.$~'
-
path: 'src/Form.php'
message: '~^Parameter \#1 \$object of method Atk4\\Ui\\View::add\(\) expects Atk4\\Ui\\View, Atk4\\Ui\\JsCallback given\.$~'
-
path: 'src/Form.php'
message: '~^Parameter \#2 \$value of method Atk4\\Ui\\View::setAttr\(\) expects string\|null, int given\.$~'
Expand Down Expand Up @@ -885,12 +870,6 @@ parameters:
-
path: 'src/UserAction/ModalExecutor.php'
message: '~^Parameter \#2 \$selector of method Atk4\\Ui\\View::on\(\) expects Atk4\\Ui\\JsExpressionable\|string\|null, array\<int, mixed\> given\.$~'
-
path: 'src/View.php'
message: '~^Parameter \#1 \$object of method Atk4\\Ui\\View::add\(\) expects Atk4\\Ui\\View, Atk4\\Ui\\JsCallback given\.$~'
-
path: 'src/VirtualPage.php'
message: '~^Parameter \#1 \$object of method Atk4\\Ui\\View::add\(\) expects Atk4\\Ui\\View, array\<int\|string, string\> given\.$~'
-
path: 'tests/JsTest.php'
message: '~^Parameter \#1 \$args of class Atk4\\Ui\\JsFunction constructor expects array, null given\.$~'
Expand Down Expand Up @@ -1146,9 +1125,6 @@ parameters:
-
path: 'src/Card.php'
message: '~^Method Atk4\\Ui\\Card::addAction\(\) has parameter \$button with no typehint specified\.$~'
-
path: 'src/Card.php'
message: '~^Method Atk4\\Ui\\Card::addAction\(\) has parameter \$executor with no typehint specified\.$~'
-
path: 'src/Card.php'
message: '~^Method Atk4\\Ui\\Card::addExtraFields\(\) has no return typehint specified\.$~'
Expand Down
2 changes: 1 addition & 1 deletion src/Behat/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function jqueryWait(string $extraWaitCondition = 'true', int $maxWaitd
}
}

throw new Exception('jQuery did not finished within a time limit');
throw new Exception('jQuery did not finish within a time limit');
}

protected function disableAnimations(): void
Expand Down
8 changes: 5 additions & 3 deletions src/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,20 @@ public function addSection(string $title = null, Model $model = null, array $fie

/**
* Add action executor to card.
*
* @param class-string<View&UserAction\ExecutorInterface> $executorClass
*/
public function addAction(Model\UserAction $action, $executor, $button = null)
public function addAction(Model\UserAction $action, $executorClass, $button = null)
{
if (!$button) {
$button = new Button([$action->caption]);
}
$btn = $this->addButton($button);

$vp = VirtualPage::addTo($this)->set(function ($page) use ($executor, $action) {
$vp = VirtualPage::addTo($this)->set(function (View $page) use ($executorClass, $action) {
$id = $this->stickyGet($this->name);

$page->add($executor = new $executor());
$executor = $page->add(new $executorClass());

$action->setEntity($action->getModel()->load($id));

Expand Down
6 changes: 3 additions & 3 deletions src/CardDeck.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class CardDeck extends View
{
public $ui = '';

/** @var string|View Card type inside this deck. */
public $card = [Card::class];
/** @var string Card type inside this deck. */
public $card = Card::class;

/** @var string default template file. */
public $defaultTemplate = 'card-deck.html';
Expand Down Expand Up @@ -144,7 +144,7 @@ public function setModel(Model $model, array $fields = null, array $extra = null

if ($count = $this->initPaginator()) {
$this->model->each(function ($m) use ($fields, $extra) {
$c = $this->cardHolder->add(Factory::factory($this->card, ['useLabel' => $this->useLabel, 'useTable' => $this->useTable]))->addClass('segment');
$c = $this->cardHolder->add(Factory::factory([$this->card], ['useLabel' => $this->useLabel, 'useTable' => $this->useTable]))->addClass('segment');
$c->setModel($m, $fields);
if ($extra) {
$c->addExtraFields($m, $extra, $this->extraGlue);
Expand Down
2 changes: 1 addition & 1 deletion src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected function init(): void
// set css loader for this form
$this->setApiConfig(['stateContext' => '#' . $this->name]);

$this->cb = $this->add(new JsCallback(), ['desired_name' => 'submit']);
$this->cb = JsCallback::addTo($this, [], [['desired_name' => 'submit']]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ public function on($event, $selector = null, $action = null, $defaults = null)
}

// create callback, that will include event as part of the full name
$this->add($cb = new JsCallback(), ['desired_name' => $event]);
$cb = JsCallback::addTo($this, [], [['desired_name' => $event]]);
if ($defaults['apiConfig'] ?? null) {
$cb->apiConfig = $defaults['apiConfig'];
}
Expand Down
2 changes: 1 addition & 1 deletion src/VirtualPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function init(): void
{
parent::init();

$this->cb = $this->add([Callback::class, 'urlTrigger' => $this->urlTrigger ?: $this->name]);
$this->cb = Callback::addTo($this, ['urlTrigger' => $this->urlTrigger ?: $this->name]);
unset($this->{'urlTrigger'});
}

Expand Down

0 comments on commit 904939a

Please sign in to comment.