Coder Social home page Coder Social logo

leo's Issues

Feedback/Idea: Use a specific library for dynamic objects.

Hi,

I've discovered your library 3 weeks ago and a colleague included it for the test in Atomium, a Drupal theme project from the European Commission.
It was the first time I saw such a mechanism to extend classes and I really like it, congratulations, it's impressive.

I liked it so much that I've decided to make a small library that everyone could use and extend too.

You can find it here: https://github.com/drupol/DynamicObjects
It's 100% tested by PHPSpec.

Do you think that Leo might use it and so get rid of the DynamicObjectTrait.php in src/ ?

Let me know what you think.

Thanks!

better alternative to print_r?

The Formatter class uses print_r($var, true) to format an object by default.

This works most of the time, but will result in an endless stream of garbage if the variable contains circular references.

The symfony VarDumper component looks pretty promising. Seems like it allows you to limit depth.

Calling `throw()` with both type and message only checks the message?

When you specify the exception message in a throw() assertion, the type check is currently bypassed.

Code to reproduce:

<?php

describe('Bug with throw()', function () {
    it('should assert type', function () {
        $actual = function () {
            $throws = function () { throw new Exception(); };

            expect($throws)->to->throw('RuntimeException');
        };

        expect($actual)->to->throw('Peridot\Leo\Responder\Exception\AssertionException');
    });

    it('should assert type even when message is specified', function () {
        $actual = function () {
            $throws = function () { throw new Exception('foobar'); };

            expect($throws)->to->throw('RuntimeException', 'foobar');
        };

        expect($actual)->to->throw('Peridot\Leo\Responder\Exception\AssertionException');
    });
});

The first test passes because Exception is not a RuntimeException. The second test fails because the message argument bypasses the type check.

This section of the code seems to be the offender, in ExceptionMatcher::doMatch():

            $message = $e->getMessage();
            if ($this->expectedMessage) {
                $this->setMessage($message);
                return $this->expectedMessage == $message;
            }
            if (!$e instanceof $this->expected) {
                return false;
            }

I tried fixing it myself but couldn't figure out how to get it to produce the correct error message in all cases.

Investigate failures under HHVM

Currently, some specs are causing errors like the following under HHVM:

  1) assert ->doesNotThrow() should throw an exception if function throws exception:
     print_r() exceeded max bytes limit
      #0 (): Closure$Peridot\Core\Test::handleErrors()
      #1 /home/travis/build/peridot-php/leo/src/Formatter/Formatter.php(91): print_r()
      #2 /home/travis/build/peridot-php/leo/src/Formatter/Formatter.php(61): Peridot\Leo\Formatter\Formatter->objectToString()
      #3 /home/travis/build/peridot-php/leo/src/Responder/ExceptionResponder.php(49): Peridot\Leo\Formatter\Formatter->getMessage()
      #4 /home/travis/build/peridot-php/leo/src/Assertion.php(224): Peridot\Leo\Responder\ExceptionResponder->respond()
      #5 /home/travis/build/peridot-php/leo/src/Assertion.php(156): Peridot\Leo\Assertion->assert()
      #6 /home/travis/build/peridot-php/leo/src/Assertion.php(117): Peridot\Leo\Assertion->request()
      #7 /home/travis/build/peridot-php/leo/src/Interfaces/Assert.php(109): Peridot\Leo\Assertion->__call()
      #8 /home/travis/build/peridot-php/leo/specs/interfaces/assert.spec.php(74): Peridot\Leo\Interfaces\Assert->doesNotThrow()
      #9 (): Closure$#24()
      #10 /home/travis/build/peridot-php/leo/src/Matcher/ExceptionMatcher.php(206): call_user_func_array()
      #11 /home/travis/build/peridot-php/leo/src/Matcher/AbstractMatcher.php(71): Peridot\Leo\Matcher\ExceptionMatcher->doMatch()
      #12 /home/travis/build/peridot-php/leo/src/Matcher/ExceptionMatcher.php(188): Peridot\Leo\Matcher\AbstractMatcher->match()
      #13 /home/travis/build/peridot-php/leo/src/Assertion.php(218): Peridot\Leo\Matcher\ExceptionMatcher->match()
      #14 /home/travis/build/peridot-php/leo/src/Assertion.php(156): Peridot\Leo\Assertion->assert()
      #15 /home/travis/build/peridot-php/leo/src/Assertion.php(117): Peridot\Leo\Assertion->request()
      #16 /home/travis/build/peridot-php/leo/src/Interfaces/Assert.php(95): Peridot\Leo\Assertion->__call()
      #17 /home/travis/build/peridot-php/leo/specs/interfaces/assert.spec.php(75): Peridot\Leo\Interfaces\Assert->throws()
      #18 (): Closure$#25()
      #19 /home/travis/build/peridot-php/leo/vendor/peridot-php/peridot/src/Core/Test.php(61): call_user_func_array()
      #20 /home/travis/build/peridot-php/leo/vendor/peridot-php/peridot/src/Core/Test.php(46): Peridot\Core\Test->executeTest()
      #21 /home/travis/build/peridot-php/leo/vendor/peridot-php/peridot/src/Core/Suite.php(112): Peridot\Core\Test->run()
      #22 /home/travis/build/peridot-php/leo/vendor/peridot-php/peridot/src/Core/Suite.php(83): Peridot\Core\Suite->runTest()
      #23 /home/travis/build/peridot-php/leo/vendor/peridot-php/peridot/src/Core/Suite.php(112): Peridot\Core\Suite->run()
      #24 /home/travis/build/peridot-php/leo/vendor/peridot-php/peridot/src/Core/Suite.php(83): Peridot\Core\Suite->runTest()
      #25 /home/travis/build/peridot-php/leo/vendor/peridot-php/peridot/src/Core/Suite.php(112): Peridot\Core\Suite->run()
      #26 /home/travis/build/peridot-php/leo/vendor/peridot-php/peridot/src/Core/Suite.php(83): Peridot\Core\Suite->runTest()
      #27 /home/travis/build/peridot-php/leo/vendor/peridot-php/peridot/src/Runner/Runner.php(57): Peridot\Core\Suite->run()
      #28 /home/travis/build/peridot-php/leo/vendor/peridot-php/peridot/src/Console/Command.php(176): Peridot\Runner\Runner->run()
      #29 /home/travis/build/peridot-php/leo/vendor/peridot-php/peridot/src/Console/Command.php(149): Peridot\Console\Command->getResult()
      #30 /home/travis/build/peridot-php/leo/vendor/symfony/console/Command/Command.php(259): Peridot\Console\Command->execute()
      #31 /home/travis/build/peridot-php/leo/vendor/symfony/console/Application.php(847): Symfony\Component\Console\Command\Command->run()
      #32 /home/travis/build/peridot-php/leo/vendor/symfony/console/Application.php(192): Symfony\Component\Console\Application->doRunCommand()
      #33 /home/travis/build/peridot-php/leo/vendor/peridot-php/peridot/src/Console/Application.php(84): Symfony\Component\Console\Application->doRun()
      #34 /home/travis/build/peridot-php/leo/vendor/symfony/console/Application.php(123): Peridot\Console\Application->doRun()
      #35 /home/travis/build/peridot-php/leo/vendor/peridot-php/peridot/src/Console/Application.php(63): Symfony\Component\Console\Application->run()
      #36 /home/travis/build/peridot-php/leo/vendor/peridot-php/peridot/bin/peridot(45): Peridot\Console\Application->run()
      #37 {main}

I'm going to shift the HHVM builds to the "allowed failures" section to get this round of repo maintenance done, but these errors should be addressed properly ASAP.

PHP syntax error

Just installed by
composer require --dev peridot-php/peridot peridot-php/leo

$ ./vendor/bin/peridot
PHP Parse error: syntax error, unexpected token "match" in /home/dev/onion/vendor/peridot-php/leo/specs/responder/responder.spec.php on line 18

$ php -v
PHP 8.1.0 (cli) (built: Nov 25 2021 20:22:03) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.0, Copyright (c) Zend Technologies
with Zend OPcache v8.1.0, Copyright (c), by Zend Technologies

$ uname -a
Linux aj 5.4.0-92-lowlatency #103-Ubuntu SMP PREEMPT Fri Nov 26 17:05:05 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

[question]peridot-php code coverage

Hi all, Thank you for your creating all peridot-php libraries. The libraries are brilliant.

I have a question. I want to get test coverage in my src directory.

First I added peridot libraries below

    "require-dev": {
        "mockery/mockery": "0.9.*",
        "fabpot/php-cs-fixer": "1.*",
        "peridot-php/peridot": "1.9.0",
        "peridot-php/leo": "1.2.0",
        "peridot-php/peridot-prophecy-plugin": "~1.0",
        "peridot-php/peridot-code-coverage-reporters": "1.0.2",
        "satooshi/php-coveralls": "~0.6"
    },

created peridot.php below.

<?php

use Evenement\EventEmitterInterface;
use Peridot\Reporter\CodeCoverage\AbstractCodeCoverageReporter;
use Peridot\Reporter\CodeCoverageReporters;

/**
 * Configure peridot.
 *
 * @param EventEmitterInterface $eventEmitter
 */
return function (EventEmitterInterface $eventEmitter) {
    (new CodeCoverageReporters($eventEmitter))->register();

    $eventEmitter->on('peridot.start', function (\Peridot\Console\Environment $environment) {
        $environment->getDefinition()->getArgument('path')->setDefault('spec');
    });

    $eventEmitter->on('code-coverage.start', function (AbstractCodeCoverageReporter $reporter) {
        $reporter->addDirectoryToWhitelist(__DIR__ . '/src')->addDirectoryToWhitelist(__DIR__ . '/spec');
    });
};

and run peridot

./vendor/bin/peridot spec/ -r clover-code-coverage --code-coverage-path "build/logs/clover.xml"

But I got exception below.

[PHP_CodeCoverage_Exception]
No code coverage driver available
peridot [options] [files]

It may be thrown at phpunit/php-code-coverage/src/CodeCoverage.php:142.

I tried to

git clone [email protected]:peridot-php/leo.git
composer install
./vendor/bin/peridot specs/ # it passes
./vendor/bin/peridot specs/ -r clover-code-coverage --code-coverage-path "build/logs/clover.xml"

But I got same exception about PHP_CodeCoverage_Exception.

Do you have any advices to get test coverage?

Feature request: Allow asserting that trigger_error() is called

PHPUnit has $this->setExpectedException('PHPUnit_Framework_Error_Warning');. Leo should provide some way of doing this too. Something like this:

expect(function () {
    trigger_error('Oh no!', E_USER_WARNING);
})->to->triggererror(E_USER_WARNING, 'Oh no!');

Memoize lazy properties if possible

According to profiling, tests end up spending a lot of time in Leo. The language chains as they stand right now are great for readability and extendability, but they are slowing tests town a tiny bit.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.