Git Product home page Git Product logo

Comments (10)

SamMousa avatar SamMousa commented on June 2, 2024 1

Well I've considered (not very thoroughly) some options:

  1. Non-static helper
  • Change Console to be a normal class that takes the streams as constructor argument
  • Add Console::__callStatic to support static calls that default to a singleton instance.
    (I think this is similiar to Laravel Facades)
  1. Static configuration of streams
  • Add public static $stdout = \STDOUT; which is overridable.
  1. Switch to echo (but this does not solve the issue for STDERR).

from yii-console.

samdark avatar samdark commented on June 2, 2024

Do you have an idea on how to fix it?

from yii-console.

SamMousa avatar SamMousa commented on June 2, 2024

Or more advanced, haven't tested this myself: https://stackoverflow.com/questions/8348927/is-there-a-way-test-stderr-output-in-phpunit

from yii-console.

schmunk42 avatar schmunk42 commented on June 2, 2024

What's about $I->seeInShellOutput() from Codeception?

Examples: https://github.com/dmstr/phd5-app/blob/master/tests/codeception/cli/1-YiiCept.php

from yii-console.

SamMousa avatar SamMousa commented on June 2, 2024

It doesn't work since it can't intercept fwrite commands.

from yii-console.

schmunk42 avatar schmunk42 commented on June 2, 2024

Hmm, I am testing all the output written by $this->stdout() this way?!

from yii-console.

SamMousa avatar SamMousa commented on June 2, 2024

Ah wait you're running new shell commands instead of running the test inside the same process.
Basically the approach you use is not about Yii at all, your tests could test any executable by executing it and checking the result.
That is not the same as testing one specific function; it would work though...

from yii-console.

schmunk42 avatar schmunk42 commented on June 2, 2024

@SamMousa Ah yes, you are right. I never got familiar with mocking all the stuff :) But, I remember having issues with STDERR also.

from yii-console.

schmunk42 avatar schmunk42 commented on June 2, 2024

@SamMousa Did you consider "mocking" fwrite in tests, like so https://www.schmengler-se.de/en/2011/03/php-mocking-built-in-functions-like-time-in-unit-tests/

from yii-console.

bscheshirwork avatar bscheshirwork commented on June 2, 2024

How about mock/DI replace Console class for tests?

from yii-console.

Related Issues (20)

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.