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 stucks #47

Closed Komanc closed 6 years ago

Komanc commented 7 years ago

Hi,

don't know if this is a right place to this issue, sorry if it is not.

Testbench stucks when I try scaffold. I tried to run it through vendor/mrtnzlml/testbench/src/run-tests (don't know another way how to put some breakpoints there, but vendor/bin/run-tests behave in the same way) and it creates in _temp/cache/ files Nette.Configurator/Container_{some_hash}.php.lock and Nette.RobotLoader/_Nette.RobotLoader/_{some_hash}. It hits https://github.com/nette/di/blob/v2.4/src/DI/ContainerLoader.php#L77 for the first time it is ok, but for the second time it stuck here. On empty web-project it was okay. Also there is no problem with this when Nette generates cache for normal application.

Maybe I have something wrong with my folder structure or bootstrap file.

I'm using Windows 10, PHP 7.0.14,

My folder structure

+---app
|   +---AdminModule
|   |   +---Presenters
|   |       +---templates
|   |           +---Apps
|   |           +---Customers
|   |           +---Dashboard
|   |           +---Profile
|   |           +---Users
|   +---config
|   +---FrontModule
|   |   +---Presenters
|   |       +---templates
|   |           +---Sign
|   +---presenters
|   |   +---templates
|   |       +---Error
|   +---router
+---html
|   +---assets
|       +---css
|       +---fonts
|       +---js
+---log
+---src
|   +---Project
|       +---Apps
|       |   +---Entity
|       +---Components
|       |   +---AppForm
|       |   +---AppsGrid
|       |   +---ChangePassword
|       |   +---CustomerForm
|       |   +---CustomersGrid
|       |   +---Grid
|       |   +---MainMenu
|       |   +---SignIn
|       |   +---UserForm
|       |   +---UsersGrid
|       +---Customers
|       |   +---Entity
|       +---Doctrine
|       +---UI
|       +---Users
|           +---Entity
|           +---Exception
+---temp
+---tests
    +---bootstrap.php

tests/bootstrap.php

<?php

require __DIR__ . '/../vendor/autoload.php';

Testbench\Bootstrap::setup(
    __DIR__ . '/_temp',
    function (\Nette\Configurator $configurator) {
        $configurator->createRobotLoader()
            ->addDirectory(__DIR__ . '/../app')
            ->addDirectory(__DIR__ . '/../src')
            ->register();

        $configurator->addParameters(
            [
                'appDir' => __DIR__ . '/../app',
                'wwwDir' => __DIR__ . '/../html',
            ]
        );

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

And in composer.json I have

"require-dev": {
    "nette/tester": "2.0.x-dev",
    "mrtnzlml/testbench": "^2.4"
},
mrtnzlml commented 7 years ago

Maybe related to the https://github.com/mrtnzlml/testbench/issues/46

In the future I am probably going to remove scaffold, because it's very problematic. It's going to be better to focus only on Testbench itself.

Komanc commented 7 years ago

Ok thanks for information. I tried to create simple test class by myself then.

And it also stucks on that https://github.com/nette/di/blob/v2.4/src/DI/ContainerLoader.php#L77 while it tries to create cache. Maybe related to #41

Don't know if this helps, but when I edited that flock in linked file to this if (!$handle || !flock($handle, LOCK_EX|LOCK_NB)) { // added LOCK_NB flag it steps into that if instead of stucking and throw exception.

I don't see into this, so I really don't know if it could be a bug in nette\di or it is there on purpose without LOCK_NB flag.

Did more research and when it "register" Doctrine it calls again https://github.com/mrtnzlml/testbench/blob/master/src/Mocks/DoctrineConnectionMock.php#L33 and tries to create Container, but there is already lock on this so it fails and because of lack of LOCK_NB it only stucks instead of throwing exception.

Hope this helps somehow.

mrtnzlml commented 7 years ago

Thanks for detailed reporting. I'll look into it. For now I can suggest only to use Nette Tester itself, because this is going to take a while to fix (not really sure how). Can you please send me following info?

php -v && php -m
composer info --installed

Thanks.

Komanc commented 7 years ago
php -v && php -m
PHP 7.0.14 (cli) (built: Dec  6 2016 15:35:54) ( ZTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Xdebug v2.5.0, Copyright (c) 2002-2016, by Derick Rethans
[PHP Modules]
bcmath
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
gd
gettext
hash
iconv
intl
json
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_pgsql
pdo_sqlite
pgsql
Phar
Reflection
session
SimpleXML
sockets
SPL
standard
tidy
tokenizer
wddx
xdebug
xml
xmlreader
xmlwriter
xsl
zip
zlib

[Zend Modules]
Xdebug
composer info --installed
adeira/monolog            v1.0.2
dg/composer-cleaner       v0.5               Victor The Cleaner: removes unnecessary files from vendor directory.
doctrine/annotations      v1.4.0             Docblock Annotations Parser
doctrine/cache            v1.6.1             Caching library offering an object-oriented API for many cache backends
doctrine/collections      v1.4.0             Collections Abstraction library
doctrine/common           v2.7.2             Common Library for Doctrine projects
doctrine/dbal             v2.5.12            Database Abstraction Layer
doctrine/inflector        v1.1.0             Common String Manipulations with regard to casing and singular/plural...
doctrine/instantiator     1.0.5              A small, lightweight utility to instantiate objects in PHP without in...
doctrine/lexer            v1.0.1             Base library for a lexer that can be used in Top-Down, Recursive Desc...
doctrine/orm              v2.5.6             Object-Relational-Mapper for PHP
kdyby/annotations         v2.3.1             Doctrine Annotations integration into Nette Framework
kdyby/console             v2.6.1             Symfony Console integration for Kdyby components
kdyby/doctrine            v3.1.2             Doctrine integration into Nette Framework
kdyby/doctrine-cache      v2.5.2             Doctrine Cache bridge for Nette Framework
kdyby/events              v3.0.2             Events for Nette Framework
kdyby/fake-session        v2.0.0             FakeSession class for Nette Framework
kdyby/monolog             v1.2.1             Integration of Monolog into Nette Framework
latte/latte               v2.4.3             Latte: the amazing template engine for PHP
monolog/monolog           1.22.1             Sends your logs to files, sockets, inboxes, databases and various web...
mrtnzlml/testbench        dev-master dc755b0 Simple integration testing tool for Nette Framework applications
nette/application         v2.4.5             Nette Application MVC Component
nette/bootstrap           v2.4.3             Nette Bootstrap
nette/caching             v2.5.3             Nette Caching Component
nette/component-model     v2.3.0             Nette Component Model
nette/database            v2.4.2             Nette Database Component
nette/di                  v2.4.8             Nette Dependency Injection Component
nette/finder              v2.4.0             Nette Finder: Files Searching
nette/forms               v2.4.4             Nette Forms: greatly facilitates web forms
nette/http                v2.4.5             Nette HTTP Component
nette/mail                v2.4.2             Nette Mail: Sending E-mails
nette/neon                v2.4.1             Nette NEON: parser & generator for Nette Object Notation
nette/php-generator       v3.0.0             🐘 Generates neat PHP code for you. Supports new PHP 7.1 features.
nette/reflection          v2.4.1             Nette PHP Reflection Component
nette/robot-loader        v2.4.2             Nette RobotLoader: comfortable autoloading
nette/safe-stream         v2.3.2             Nette SafeStream: Atomic Operations
nette/security            v2.4.1             Nette Security: Access Control Component
nette/tester              dev-master b14d4a7 Tester: enjoyable unit testing in PHP with code coverage reporter. ▒...
nette/utils               v2.4.5             Nette Utility Classes
nextras/datagrid          dev-master 03b1839 Datagrid component for Nette Framework.
nextras/latte-macros      v2.0.0             Macros for Latte from Nette Framework.
psr/log                   1.0.2              Common interface for logging libraries
symfony/console           v3.2.7             Symfony Console Component
symfony/debug             v3.2.7             Symfony Debug Component
symfony/polyfill-mbstring v1.3.0             Symfony polyfill for the Mbstring extension
tracy/tracy               v2.4.6             Tracy: useful PHP debugger
Komanc commented 7 years ago

I commented calling of prepareDoctrine(). And it's "working". I assumed it will be using Doctrine as regular application, but I can't see any drawbacks for me. This satisfy my demands for now. I have never been using tests and this looks so cool from my perspective. Thank you for this :)

mrtnzlml commented 6 years ago

Scaffold removed in master branch.