OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums Forums OroPlatform OroPlatform – Programming Questions Functional Tests 401

This topic contains 42 replies, has 4 voices, and was last updated by  archy_bold 7 years, 10 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #33722

    jakabadambalazs
    Participant

    Hi,

    I followed your guide about setting up the test environment and writting functional tests. I am stuck on my very first testIndex action because I get 401 (authentication failure) where I am expecting 200.

    I did:

    configured config_test.yml

    I see my db populated and user exists with username “admin”

    and this my my test:

    … and this is what i get:

    :-(

    I even tried without luck:

    Where do you think I made a mistake out something?


    oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)

Viewing 12 replies - 31 through 42 (of 42 total)
  • Author
    Replies
  • #33753

    jakabadambalazs
    Participant

    Ok, I am just so happy that finally I can do functional tests that I don’t care I’ll make 2 separate tests then!

    Looking at optimistically, it was a good chance to review my code and check on some oro internals.

    Thanks again for your help!

    one more question(unrelated to this problem): What is the reason why you run your unit tests on Travis CI but not the functional tests? Is it because it would be too time consuming to deploy, configure, install a fully working OroPlatform?


    oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)

    #33754

    Yevhen Shyshkin
    Participant

    We just haven’t done this yet. :) We have our own internal CI and travis is just an addiotional tool to simplify testing of commnity PRs.

    #33755

    jakabadambalazs
    Participant

    Dear @yshyshkin,

    I have identified what makes the functional tests fail if executed togeter with the unit tests!

    It is:

    If I comment them out both unit and functional test work side by side.
    If I use either of them (or probably some other entity connected to the authentication) I go back to 401 stuff.

    IMHO, these test sutes should be executed in differenct testsuites because they have different responsibilities.

    I agree, but if I want to get overall coverage I need to do them together (hmmm… is this true?)

    Anyways, why should the mock objects interfere with the authentication process?


    oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)

    #33756

    jakabadambalazs
    Participant

    Actually, as soon as i put in any of my unit tests even this:

    where User is Oro\Bundle\UserBundle\Entity\User

    the functional tests fail


    oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)

    #33757

    Yevhen Shyshkin
    Participant

    Sure, because this class has property $avatar that is not defined correctly.

    #33758

    jakabadambalazs
    Participant

    But I am using the $user (either mock od real entity) object in my unit test just as you do in https://github.com/orocrm/crm/blob/master/src/OroCRM/Bundle/AccountBundle/Tests/Unit/Entity/AccountTest.php#L76

    This is not where the test fails – in fact the following unit test passes OK:

    but all functional tests will fail (with 401) afterwards complaining about $avatar property

    if I comment out the above unit test the functional tests will pass

    What is not clear to me is how/why this unit test is affecting the functional tests


    oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)

    #33759

    Yevhen Shyshkin
    Participant

    Unit tests do not use extended entity functionality, but functional test do.

    Extended entities are inclided with intermediate parent class (ExtendUser for User entity). In unit tests this entity uses empty parent class, but in functinal this class has an alias that adds additional properties ($avatar in our case). You can check that using class_parents function.

    #33760

    jakabadambalazs
    Participant

    ok i’ll try do do that.

    In the meanwhile I have found something interesting:

    If I execute both the unit and the functional tests together like this:

    first unit tests then functional tests – Functional tests will fail

    If I invert the order like this:

    both unit and functional tests will pass


    oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)

    #33761

    jakabadambalazs
    Participant

    Extended entities are inclided with intermediate parent class (ExtendUser for User entity). In unit tests this entity uses empty parent class, but in functional this class has an alias that adds additional properties ($avatar in our case)…

    Is it because in functional tests we initialize the kernel which will spin up all the bundles (like the EntityExtendBundle) so that we have extended properties (like $avatar)? and this does not happen when we do unit tests?

    So that’s why if I execute functional tests before unit tests all works but if I do it the other way around functional tests will fail (because the entities are already “cached” without extended properties and methods).


    oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)

    #33762

    kelton23om
    Participant

    Hi guys,

    I am facing the same issue, but it appears when i launch oro commands like migrations during the extend cache refresh.

    It is very odd because, the code seems good, the cache files too.. but the issue always appear..

    #33763

    archy_bold
    Participant

    Sorry to resurrect an old thread, but I’ve run into the same issues having just added a test with the following line to one of my Unit tests:

    And the error:

    My app/phpunit.xml file is the default one with my tests added in.

    And I run the following command:

    Removing the mocks allows the test to run but it’s not ideal. I tried to drop my database and re-install to no avail. Was there a solid solution to the problem?

    Thanks,
    Simon

    #33764

    archy_bold
    Participant

    Interestingly, this only happened to me in a method that was used as a @dataProvider. When I moved the code out, into the test case itself, the error was gone.

    Was that the same issue as the initial one?

Viewing 12 replies - 31 through 42 (of 42 total)

The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.

Back to top