Git Product home page Git Product logo

Comments (10)

kenjis avatar kenjis commented on May 25, 2024

If we do unit tests, we should test only a hook class.
This is my test case: https://github.com/kenjis/codeigniter-tettei-apps/blob/develop/application/tests/hooks/Convert_encoding_test.php#L13-27
The hook converts character encoding of $_POST on some conditions at pre_system.

Do you want to do functional tests including hooks? If so, we have to implement something to support it.

Anyway, first of all, what do you want to test?

from ci-phpunit-test.

RodolfoSilva avatar RodolfoSilva commented on May 25, 2024

I have one library for check it is authorized call method, and this call in post_controller_constructor.

from ci-phpunit-test.

kenjis avatar kenjis commented on May 25, 2024

If I were you, I write tests only for the library, and write controller tests (hook is just ignored). I think it is enough.

But do you want controller tests to call the hook?

from ci-phpunit-test.

RodolfoSilva avatar RodolfoSilva commented on May 25, 2024

I want to be sure that the hook is working.
But I'm going to follow your suggestion that also works.

from ci-phpunit-test.

kenjis avatar kenjis commented on May 25, 2024

I want to be sure that the hook is working.

If your config for hooks is right, it must be working. It is CodeIgniter's specification.
We don't have to test if we trust CodeIgniter.

And I also test my application with Selenium for acceptance test. It probably test hooks are working or not.

I'm not sure we need support testing with hooks. I ignored hooks, because

  1. It is not needed for unit testing
  2. too many hook points, so I was not sure how to implement

But if you really want to do it, you can add code to call hooks to request() method.

from ci-phpunit-test.

kenjis avatar kenjis commented on May 25, 2024

See #23

from ci-phpunit-test.

RodolfoSilva avatar RodolfoSilva commented on May 25, 2024

Improved now with #23

from ci-phpunit-test.

kenjis avatar kenjis commented on May 25, 2024

I found a hack to add autoloader for controllers in pre_system hook.

3 . Using an autoload function with hooks (the slow and right way)
http://avenir.ro/codeigniter-tutorials/no-more-my_controller-how-you-can-create-more-than-one-base-controller/

In this case, we need to call pre_system before executing controllers.
pre_system is called in PHPUnit bootstrap (called in core/CodeIgniter.php in CIPHPUnitTest::init()).

So there is no problem.

from ci-phpunit-test.

kenjis avatar kenjis commented on May 25, 2024

I added docs on hooks in current ci-phpunit-test:
https://github.com/kenjis/ci-phpunit-test/blob/master/docs/HowToWriteTests.md#hooks

from ci-phpunit-test.

kenjis avatar kenjis commented on May 25, 2024

I think the current specification is good enough. So I'm planning to close the issue.
If anyone has any opinion about it, please post.

from ci-phpunit-test.

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.