Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

I cant use unit-test, "Cannot bind an instance to a static closure" happens.

I would like to unit-test some of my codes. Im using the newest Phpunit. My phpunit.xml:

<?php<phpunit  bootstrap="../bootstrap.php" backupGlobals="false" backupStaticAttributes="false" verbose="true" colors="false" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" syntaxCheck="true">
  <testsuites>
    <testsuite name="sdf">
      <file>cxvcxvcxxcv.php</file>
    </testsuite>
  </testsuites>
</phpunit>

that bootstrap.php:

<?php
\Phalcon\Di::reset();
\Phalcon\Di::setDefault(new \Phalcon\DI\FactoryDefault());

\Phalcon\Di::getDefault()->setShared('t', function() {
  ...
});

and now if I would like to use this from a static method:

<?php
\Phalcon\Di::getDefault()->get('t');

it dies:

Cannot bind an instance to a static closure

what it can be?

its Php 5.6.16 and Phalcon 2.1.0b



6.8k
Accepted
answer
edited Mar '16

Try to work around this documentation

https://docs.phalconphp.com/en/latest/reference/unit-testing.html

I am using unit tests with phalcon with my own UnitTestCase, which supports internal DI object. You can completely omit DI section in your bootstrap and use only DI object from UnitTestCase, set it as default and dynamicaly register services which are needed for particular unit test.



10.9k

yea, right, I didnt see the documentation havin unit-test chapter. I was using it as the old fashion way.