mrtnzlml-archive / testbench

:green_apple: Simple integration testing tool for Nette applications
http://zlml.cz/jednoduche-testovani-pro-uplne-kazdeho
41 stars 13 forks source link

Scaffold not working even on nette/sandbox #32

Closed Valicek1 closed 7 years ago

Valicek1 commented 8 years ago

vendor/bin/run-tests --scaffold tests/bootstrap.php does not work propertly, even on plain nette sandbox. Im not able to explain it very well, but i'll show you how to reproduce.

1, Create sandbox vasek@W520 ~ $ mkdir /tmp/testbench 0 ✓ vasek@W520 ~ $ cd /tmp/testbench/ 0 ✓ vasek@W520 /tmp/testbench $ composer create-project nette/sandbox .

Installing nette/sandbox (v2.4.0)
  - Installing nette/sandbox (v2.4.0)
    Loading from cache

Created project in .
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing nette/utils (dev-master 2254088)
    Cloning 22540888735c1cba7f0e27f12b61c8ef31749f3c

  - Installing nette/finder (dev-master b7b5421)
    Cloning b7b54213f150461600e117b4d85cfba9a36a6838

  - Installing nette/caching (dev-master da827a7)
    Cloning da827a7f4704cf99abcba2973496d4f2c623b32f

  - Installing nette/reflection (dev-master bed1704)
    Cloning bed17041523639ff60286fae74637c28a4f06b1a

  - Installing nette/http (dev-master 3fb64f5)
    Cloning 3fb64f5ae5d1e161cb8ab12de1fb9958cea8a50b

  - Installing nette/component-model (dev-master 51548f5)
    Cloning 51548f53c09676dc13bec6fdd980c25bc746c6f8

  - Installing nette/application (dev-master 82330d4)
    Cloning 82330d4a374a619ca51da59db76408454c82f18e

  - Installing nette/php-generator (dev-master 41058dc)
    Cloning 41058dcef10c149751643cb95f5709649f8eaeaa

  - Installing nette/neon (dev-master faf208e)
    Cloning faf208ea4035b15bf4a8147cdfb3c2c318526425

  - Installing nette/di (dev-master 4f05d0c)
    Cloning 4f05d0c17e62e5cbee61cb38046fc0f39e50ff1a

  - Installing nette/bootstrap (dev-master 600b179)
    Cloning 600b17955d7ebf3f203cbf8e21803d5ce406e8d6

  - Installing nette/database (dev-master aedf176)
    Cloning aedf17629100545219378edaca7db4ce9e1aa1f1

  - Installing nette/forms (dev-master 612c74b)
    Cloning 612c74b334ed1823c30eedaf38c96578e7837142

  - Installing nette/mail (dev-master 3847437)
    Cloning 38474377b04ce30f9814da56cd34281f6a877854

  - Installing nette/robot-loader (dev-master afbcc4a)
    Cloning afbcc4a578960f0ec602c87bb142be34e7455b34

  - Installing nette/safe-stream (dev-master 2e4bd99)
    Cloning 2e4bd99b9807ed405e3e30edaa95bac078a1aba9

  - Installing nette/security (dev-master d506dc2)
    Cloning d506dc273daae4fcc91017ac08980b0c7c55b9cd

  - Installing latte/latte (dev-master 2e6ef07)
    Cloning 2e6ef07120201a6277bef2cb6d2e5d172cdae559

  - Installing tracy/tracy (dev-master 753b7d2)
    Cloning 753b7d294c8de596cdc9f07cd47c4337e5d0924e

  - Installing dg/adminer-custom (v1.7.2)
    Loading from cache

  - Installing nette/tester (v1.7.1)
    Loading from cache

nette/utils suggests installing ext-gd (to use Image)
Writing lock file
Generating autoload files

2, Install nette/tester from dev-master 0 ✓ vasek@W520 /tmp/testbench $ composer require --dev nette/tester:dev-master

./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Removing nette/tester (v1.7.1)
  - Installing nette/tester (dev-master 7d29c02)
    Cloning 7d29c02f3216a1c4debe4c6475830b5884786922

Writing lock file
Generating autoload files

3, Install testbench 0 ✓ vasek@W520 /tmp/testbench $ composer require --dev mrtnzlml/testbench

Using version ^2.3 for mrtnzlml/testbench
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing kdyby/fake-session (v2.0.0)
    Loading from cache

  - Installing mrtnzlml/testbench (v2.3.1)
    Loading from cache

mrtnzlml/testbench suggests installing kdyby/doctrine (Allows enhanced database tests using Doctrine)
mrtnzlml/testbench suggests installing kdyby/doctrine-dbal-batchimport (Allows SQL scripts import for Doctrine (required with kdyby/doctrine))
mrtnzlml/testbench suggests installing zenify/doctrine-migrations (Migrate database to the fresh state)
Writing lock file
Generating autoload files

4, configure DB etc.. 0 ✓ vasek@W520 /tmp/testbench $ vim app/config/config.local.neon 0 ✓ vasek@W520 /tmp/testbench $ cat app/config/config.local.neon

parameters:

database:
    dsn: 'mysql:host=127.0.0.1;dbname=test'
    user: tester
    password: tester
    options:
        lazy: yes

testbench:
    sqls:
        - %testsDir%/../import.sql

0 ✓ vasek@W520 /tmp/testbench $ vim tests/bootstrap.php 0 ✓ vasek@W520 /tmp/testbench $ cat tests/bootstrap.php

<?php
include __DIR__ . '/../vendor/autoload.php';

Testbench\Bootstrap::setup(__DIR__ . '/_temp', function (\Nette\Configurator $configurator) {
    $configurator->createRobotLoader()->addDirectory([
        __DIR__ . '/../app',  ])
        ->register();
    $configurator->addParameters([
        'appDir' => __DIR__ . '/../app',
        'testsDir' => __DIR__,
    ]);

    $configurator->addConfig(__DIR__ . '/../app/config/config.neon');
    $configurator->addConfig(__DIR__ . '/../app/config/config.local.neon');
    //$configurator->addConfig(__DIR__ . '/tests.neon');
});

0 ✓ vasek@W520 /tmp/testbench $ rm tests/ bootstrap.php ExampleTest.phpt
0 ✓ vasek@W520 /tmp/testbench $ rm tests/ExampleTest.phpt 0 ✓ vasek@W520 /tmp/testbench $ cat > import.sql <<"EOF"

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) COLLATE utf8mb4_bin NOT NULL,
  `email` varchar(50) COLLATE utf8mb4_bin NOT NULL,
  `name` varchar(50) COLLATE utf8mb4_bin NOT NULL,
  `password` varchar(70) COLLATE utf8mb4_bin NOT NULL,
  `role` varchar(20) COLLATE utf8mb4_bin NOT NULL DEFAULT 'guest',
  `registered` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin

EOF 5, Run 0 ✓ vasek@W520 /tmp/testbench $ vendor/bin/run-tests --scaffold tests/bootstrap.php

ReflectionException: Property App\Presenters\BasePresenter::$response does not exist

in src/Scaffold/TestsGenerator.php(193) 
in src/Scaffold/TestsGenerator.php(193) ReflectionProperty->__construct()
in src/Scaffold/TestsGenerator.php(142) Testbench\Scaffold\TestsGenerator->getResponse()
in testbench/src/Runner.php(62) Testbench\Scaffold\TestsGenerator->generateTests()
in testbench/src/run-tests(11) Testbench\Runner->prepareArguments()

255 ✗ vasek@W520 /tmp/testbench $

mrtnzlml commented 8 years ago

This is weird. I tried to follow your steps as much as possible, but it work for me fine. Does your BasePresenter extend Nette\Application\UI\Presenter? Because in pure sandbox there is $response (vendor/nette/application/src/Application/UI/Presenter.php:53).

I cannot understand what is going on and cannot reproduce it... :-(

Valicek1 commented 8 years ago

Yes, HomepagePresenter is extending BasePresenter, BasePresenter extends Nette\Application\UI\Presenter

dump($this instanceof BasePresenter);  # TRUE
dump($this instanceof \Nette\Application\UI\Presenter); # TRUE

I also tried

dump($this->response); # Cannot read an undeclared property App\Presenters\HomepagePresenter::$response

And - I have tried it with PHP 7 (Arch linux distro), PHP 7.1 (custom compiled) and PHP 5.6.23 (Arch - custom compiled + Debian distro) - always the same problem, with bare sandbox

mrtnzlml commented 8 years ago

You have to access $response like this. I'll give it one more (more deeply) try. Stay tuned...

mrtnzlml commented 7 years ago

Cannot reproduce.

jtojnar commented 7 years ago

I just came across this error. I was able to fix it by replacing get_parent_class($service) for '\Nette\Application\UI\Presenter'.