xmlsquad / xml-authoring-library

A place to put code that is reused by many commands which are part of the [xml-authoring-tools suite](https://github.com/forikal-uk/xml-authoring-tools).
Apache License 2.0
0 stars 0 forks source link

The AbstractCommand test fails #1

Closed Finesse closed 6 years ago

Finesse commented 6 years ago

I installed the repository, switched to the upgrade-to-0.2 branch, installed the dependencies (composer install), run the tests (composer test) and got the following error:

> phpunit
PHPUnit 7.2.2 by Sebastian Bergmann and contributors.

..E..............................                                 33 / 33 (100%)

Time: 211 ms, Memory: 6.00MB

There was 1 error:

1) Forikal\Library\Tests\Command\AbstractCommandTest::getConfigFilenameTest with data set #1 ('xml-authoring-library', '~/forikal-uk-xml-authoring-library')
Symfony\Component\Filesystem\Exception\FileNotFoundException: Configuration file not found.

~/forikal-uk-xml-authoring-library/src/Command/AbstractCommand.php:78
~/forikal-uk-xml-authoring-library/tests/Command/AbstractCommandTest.php:35

ERRORS!
Tests: 33, Assertions: 43, Errors: 1.
Script phpunit handling the test event returned with error code 2

Looks like there must be a file in the root directory but it doesn't exist.

Finesse commented 6 years ago

BTW, let's move AbstractCommand to the src/Console directory so all the console helpers stay in a single directory?

igormukhingmailcom commented 6 years ago

It was maybe some old version? Tests passing for me:

Igors-MacBook-Pro:xml-authoring-library igor$ git pull origin master
remote: Counting objects: 43, done.
remote: Compressing objects: 100% (29/29), done.
remote: Total 43 (delta 28), reused 25 (delta 14), pack-reused 0
Unpacking objects: 100% (43/43), done.
From github.com:forikal-uk/xml-authoring-library
 * branch            master     -> FETCH_HEAD
   633ffaf..9b6859b  master     -> origin/master
Updating 633ffaf..9b6859b
Fast-forward
 HowTo-GoogleAPISetup.md                 |   8 ++++--
 README.md                               |  47 +++++++++++++++++---------------
 src/GoogleAPI/GoogleAPIClient.php       | 242 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
 tests/GoogleAPI/GoogleAPIClientTest.php |  77 +++++++++++++++++++++++++++++++++++++++++++++++++---
 4 files changed, 313 insertions(+), 61 deletions(-)
Igors-MacBook-Pro:xml-authoring-library igor$ vendor/bin/phpunit 
PHPUnit 7.2.2 by Sebastian Bergmann and contributors.

......................................                            38 / 38 (100%)

Time: 383 ms, Memory: 8.00MB

OK (38 tests, 56 assertions)
Finesse commented 6 years ago

@igormukhingmailcom Try to install the package from scratch:

$ mkdir xml-library && cd xml-library && git clone https://github.com/forikal-uk/xml-authoring-library.git . && composer install && composer test
Cloning into '.'...
remote: Counting objects: 199, done.
remote: Compressing objects: 100% (137/137), done.
remote: Total 199 (delta 94), reused 135 (delta 49), pack-reused 0
Receiving objects: 100% (199/199), 43.24 KiB | 4.80 MiB/s, done.
Resolving deltas: 100% (94/94), done.
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 45 installs, 0 updates, 0 removals
  - Installing psr/log (1.0.2): Downloading (100%)         
  - Installing symfony/debug (v4.1.0): Downloading (100%)         
  - Installing symfony/polyfill-mbstring (v1.8.0): Downloading (100%)         
  - Installing symfony/console (v3.4.11): Downloading (100%)         
  - Installing symfony/polyfill-ctype (v1.8.0): Downloading (100%)         
  - Installing symfony/yaml (v3.4.11): Downloading (100%)         
  - Installing symfony/filesystem (v3.4.11): Downloading (100%)         
  - Installing sebastian/version (2.0.1): Downloading (100%)         
  - Installing sebastian/resource-operations (1.0.0): Downloading (100%)
  - Installing sebastian/recursion-context (3.0.0): Downloading (100%)         
  - Installing sebastian/object-reflector (1.1.1): Downloading (100%)         
  - Installing sebastian/object-enumerator (3.0.3): Downloading (100%)         
  - Installing sebastian/global-state (2.0.0): Downloading (100%)         
  - Installing sebastian/exporter (3.1.0): Downloading (100%)         
  - Installing sebastian/environment (3.1.0): Downloading (100%)         
  - Installing sebastian/diff (3.0.0): Downloading (100%)         
  - Installing sebastian/comparator (3.0.0): Downloading (100%)         
  - Installing phpunit/php-timer (2.0.0): Downloading (100%)         
  - Installing phpunit/php-text-template (1.2.1): Downloading (100%)         
  - Installing phpunit/php-file-iterator (2.0.0): Downloading (100%)         
  - Installing theseer/tokenizer (1.1.0): Downloading (100%)         
  - Installing sebastian/code-unit-reverse-lookup (1.0.1): Downloading (100%)
  - Installing phpunit/php-token-stream (3.0.0): Downloading (100%)         
  - Installing phpunit/php-code-coverage (6.0.7): Downloading (100%)         
  - Installing doctrine/instantiator (1.1.0): Downloading (100%)         
  - Installing webmozart/assert (1.3.0): Downloading (100%)         
  - Installing phpdocumentor/reflection-common (1.0.1): Downloading (100%)
  - Installing phpdocumentor/type-resolver (0.4.0): Downloading (100%)         
  - Installing phpdocumentor/reflection-docblock (4.3.0): Downloading (100%)
  - Installing phpspec/prophecy (1.7.6): Downloading (100%)         
  - Installing phar-io/version (1.0.1): Downloading (100%)         
  - Installing phar-io/manifest (1.0.1): Downloading (100%)         
  - Installing myclabs/deep-copy (1.8.0): Downloading (100%)         
  - Installing phpunit/phpunit (7.2.3): Downloading (100%)         
  - Installing psr/http-message (1.0.1): Downloading (100%)         
  - Installing guzzlehttp/psr7 (1.4.2): Downloading (100%)         
  - Installing guzzlehttp/promises (v1.3.1): Downloading (100%)         
  - Installing guzzlehttp/guzzle (6.3.3): Downloading (100%)         
  - Installing phpseclib/phpseclib (2.0.11): Downloading (100%)         
  - Installing monolog/monolog (1.23.0): Downloading (100%)         
  - Installing firebase/php-jwt (v5.0.0): Downloading (100%)         
  - Installing google/apiclient-services (v0.62): Downloading (100%)         
  - Installing psr/cache (1.0.1): Downloading (100%)         
  - Installing google/auth (v1.3.0): Downloading (100%)         
  - Installing google/apiclient (v2.2.1): Downloading (100%)         
symfony/console suggests installing symfony/event-dispatcher ()
symfony/console suggests installing symfony/lock ()
symfony/console suggests installing symfony/process ()
sebastian/global-state suggests installing ext-uopz (*)
phpunit/php-code-coverage suggests installing ext-xdebug (^2.6.0)
phpunit/phpunit suggests installing phpunit/php-invoker (^2.0)
phpunit/phpunit suggests installing ext-xdebug (*)
phpseclib/phpseclib suggests installing ext-libsodium (SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.)
phpseclib/phpseclib suggests installing ext-gmp (Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.)
monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)
monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
monolog/monolog suggests installing graylog2/gelf-php (Allow sending log messages to a GrayLog2 server)
monolog/monolog suggests installing mongodb/mongodb (Allow sending log messages to a MongoDB server via PHP Driver)
monolog/monolog suggests installing php-amqplib/php-amqplib (Allow sending log messages to an AMQP server using php-amqplib)
monolog/monolog suggests installing php-console/php-console (Allow sending log messages to Google Chrome)
monolog/monolog suggests installing rollbar/rollbar (Allow sending log messages to Rollbar)
monolog/monolog suggests installing ruflin/elastica (Allow sending log messages to an Elastic Search server)
monolog/monolog suggests installing sentry/sentry (Allow sending log messages to a Sentry server)
google/apiclient suggests installing cache/filesystem-adapter (For caching certs and tokens (using Google_Client::setCache))
Writing lock file
Generating autoload files
> phpunit
PHPUnit 7.2.3 by Sebastian Bergmann and contributors.

..E...................................                            38 / 38 (100%)

Time: 266 ms, Memory: 6.00MB

There was 1 error:

1) Forikal\Library\Tests\Command\AbstractCommandTest::getConfigFilenameTest with data set #1 ('xml-authoring-library', '~/xml-library')
Symfony\Component\Filesystem\Exception\FileNotFoundException: Configuration file not found.

~/xml-library/src/Command/AbstractCommand.php:76
~/xml-library/tests/Command/AbstractCommandTest.php:39

ERRORS!
Tests: 38, Assertions: 55, Errors: 1.
Script phpunit handling the test event returned with error code 2
igormukhingmailcom commented 6 years ago

If you clone repo to default location like this:

git clone https://github.com/forikal-uk/xml-authoring-library.git
cd xml-authoring-library
composer install && composer test

Tests will not fail (as far as one of them refers to repo name xml-authoring-library and it should be present)

Finesse commented 6 years ago

@igormukhingmailcom You are right, the test doesn't fail if the repository is located in a directory called xml-authoring-library. I think a note about this should be added somewhere. Or the test should not rely on the directory name.

forikal-uk commented 6 years ago

I am getting an error too.

$ composer install && composer test
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files
> phpunit
PHPUnit 7.2.6 by Sebastian Bergmann and contributors.

E...E.................................                            38 / 38 (100%)

Time: 157 ms, Memory: 6.00MB

There were 2 errors:

1) Forikal\Library\Tests\Command\AbstractCommandTest::getConfigFilenameExceptionTest
realpath(): open_basedir restriction in effect. File(/Users) is not within the allowed path(s): (/usr/local/bin:/Users/x:/var/folders/vc:/usr/bin/php)

/Users/x/Documents/Projects/XmlAuthoringSuite/xml-authoring-library/src/Command/AbstractCommand.php:87
/Users/x/Documents/Projects/XmlAuthoringSuite/xml-authoring-library/src/Command/AbstractCommand.php:74
/Users/x/Documents/Projects/XmlAuthoringSuite/xml-authoring-library/tests/Command/AbstractCommandTest.php:25

2) Forikal\Library\Tests\Command\AbstractCommandTest::isRootDirectoryTest with data set #1 ('/', true)
realpath(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/usr/local/bin:/Users/x:/var/folders/vc:/usr/bin/php)

/Users/x/Documents/Projects/XmlAuthoringSuite/xml-authoring-library/src/Command/AbstractCommand.php:87
/Users/x/Documents/Projects/XmlAuthoringSuite/xml-authoring-library/tests/Command/AbstractCommandTest.php:65

ERRORS!
Tests: 38, Assertions: 53, Errors: 2.
Script phpunit handling the test event returned with error code 2
$ pwd
/Users/x/Documents/Projects/XmlAuthoringSuite/xml-authoring-library

I think it might be simply because there is no config file being found.


No worries though. I write this just for the record. I can fix it.

forikal-uk commented 6 years ago

Actually, I have tried adding a config file and the test is still failing. So, I appear to have been wrong about assuming the missing config is the cause of the failing tests.


$ pwd
/Users/x/Documents/Projects/XmlAuthoringSuite/xml-authoring-library
$ cp ../xmlauthor-example-command/scapesettings.yaml.dist ./scapesettings.yaml
$ composer update && composer test
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
> phpunit
PHPUnit 7.2.6 by Sebastian Bergmann and contributors.

E...E.................................                            38 / 38 (100%)

Time: 207 ms, Memory: 6.00MB

There were 2 errors:

1) Forikal\Library\Tests\Command\AbstractCommandTest::getConfigFilenameExceptionTest
realpath(): open_basedir restriction in effect. File(/Users) is not within the allowed path(s): (/usr/local/bin:/Users/x:/var/folders/vc:/usr/bin/php)

/Users/x/Documents/Projects/XmlAuthoringSuite/xml-authoring-library/src/Command/AbstractCommand.php:87
/Users/x/Documents/Projects/XmlAuthoringSuite/xml-authoring-library/src/Command/AbstractCommand.php:74
/Users/x/Documents/Projects/XmlAuthoringSuite/xml-authoring-library/tests/Command/AbstractCommandTest.php:25

2) Forikal\Library\Tests\Command\AbstractCommandTest::isRootDirectoryTest with data set #1 ('/', true)
realpath(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/usr/local/bin:/Users/x:/var/folders/vc:/usr/bin/php)

/Users/x/Documents/Projects/XmlAuthoringSuite/xml-authoring-library/src/Command/AbstractCommand.php:87
/Users/x/Documents/Projects/XmlAuthoringSuite/xml-authoring-library/tests/Command/AbstractCommandTest.php:65

ERRORS!
Tests: 38, Assertions: 53, Errors: 2.
Script phpunit handling the test event returned with error code 2
forikal-uk commented 6 years ago

I think the open_ base directory is causing an error before the exception has a chance to kick in.

The AbstractCommandTest.php test actually tries to test the root:


    /**
     * @return array
     */
    public function isRootDirectoryDataProvider()
    {
        return [
            ['/some/path', false],
            ['/', true],
        ];
    }

So, I guess that test will never pass while my open base directory settings are blocking it.

So, it needs a rethink.

I did specify that we should search for the config file all the way up to the root, so it is my design that is broken. I, since, added the open base directory setting - so that has had side effects.

We don't really want to " search for the config file all the way up to the root" we really need to " search for the config file all the way up to the limit of scope of the system's open directories".

So, I believe the AbstractCommand's "isRootDirectory" needs to be changed to "isHighestParentDirectory" or something.

forikal-uk commented 6 years ago

Perhaps the getConfigFilename method should keep searching while directoryIsOpenToScript

We could just use is_readable

Returns TRUE if the file or directory specified by filename exists and is readable, FALSE otherwise.

forikal-uk commented 6 years ago

I shall have to do a find and replace

from:

isRootDirectory

to

isReadableDirectory

and add some feedback to the error message to hint at open_base dir settings.

forikal-uk commented 6 years ago

I think my bug was a separate issue to the bug. So, I will create a separate bug report.

See: #3

forikal-uk commented 6 years ago

I am closing this issue because I believed the original bug was resolved.