Comments

iMiksu created an issue. See original summary.

imiksu’s picture

Issue summary: View changes
bojanz’s picture

Among other things, we need a unit test for the CartProvider.

jefuri’s picture

Assigned: Unassigned » jefuri
jefuri’s picture

Status: Active » Needs review
StatusFileSize
new13.67 KB

PHPUnit test created for the cartprovider. First try ever on creating unit test, so please don't hate :P.

mglaman’s picture

Status: Needs review » Needs work

PR: https://github.com/commerceguys/commerce/pull/259

Tests failing. Cart also got added.

mglaman’s picture

StatusFileSize
new13.67 KB

Closed PR; here is original patch from PR.

kekkis’s picture

Assigned: jefuri » kekkis

Working on this as part of the Finnish monthly Drupal sprint.

imiksu’s picture

I couldn't run the test. I'm not sure yet is it just me or the patch.

I was able to run OrderTest, but not the new

miksu-work:web miksu$ php ./core/scripts/run-tests.sh --url "http://localhost" --class "Drupal\Tests\commerce_order\Kernel\Entity\OrderTest"

Drupal test run
---------------

Tests to be run:
  - Drupal\Tests\commerce_order\Kernel\Entity\OrderTest

Test run started:
  Saturday, May 21, 2016 - 14:39

Test summary
------------

Drupal\Tests\commerce_order\Kernel\Entity\OrderTest            1 passes                                      

Test run duration: 3 sec

However, I was able to find the test on the list:

miksu-work:web miksu$ php ./core/scripts/run-tests.sh --list | grep Cart
 - Drupal\commerce_cart\Tests\AddToCartFormTest
 - Drupal\commerce_cart\Tests\CartRefreshTest
 - Drupal\commerce_cart\Tests\CartTest
 - Drupal\Tests\commerce_cart\Unit\CartProviderTest

But not run it:

miksu-work:web miksu$ php ./core/scripts/run-tests.sh --url "http://localhost" --class "Drupal\Tests\commerce_cart\Unit\CartProviderTest"
  ERROR: Test class not found: Drupal\Tests\commerce_cart\Unit\CartProviderTest
  Did you mean?
  - Drupal\Tests\commerce_cart\Unit\CartProviderTest
kekkis’s picture

Assigned: kekkis » Unassigned

The patch applies cleanly but as the namespace is wrong in the test class file, run-tests.sh cannot find the class. I will see if I can find the time to provide a PR for that.

Additionally, after fixing the namespace issue, the test fails because the StoreInterface does not provide a method called id.

borisson_’s picture

StatusFileSize
new9.03 KB
new12.91 KB

I did a little bit of extra work on the test, it still fails - but went from 20+ messages to 4 - so that's an improvement I'd say.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new1.46 KB
new13 KB
borisson_’s picture

StatusFileSize
new7.92 KB

Unit test is now green.

borisson_’s picture

StatusFileSize
new2.27 KB
new13.97 KB
new13.75 KB

Went trough the test again to see if I could improve / add documentation, so attached is that.

I can open a pull-request as well if that's preferred?

bojanz’s picture

Title: Improve test coverage of cart » Add a test for CartProvider
Status: Needs review » Needs work

Retitling for clarity.

Reviewed the patch and consulted with mglaman.
The amount of mocking involved makes me think that the test is too bound to the actual implementation, and therefore not useful enough.
Our general policy has been to use kernel tests for functionality that's tied to the entity api, and I think we'd benefit a lot from doing the same here.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new19.45 KB
new5.47 KB

Changed this to a kernel test. Only contains the anonymous user part.

borisson_’s picture

StatusFileSize
new5.14 KB
new8.15 KB

This should now test the same things as #14.

borisson_’s picture

StatusFileSize
new1012 bytes
new8.14 KB

As discussed on irc, now uses EntityKernelTestBase as a baseclass.

borisson_’s picture

StatusFileSize
new4.59 KB
new7.82 KB

I changed the user creation with $this->createUser();, this revealed that I actually loaded the anonymous user twice in the previous tests. So this now fails.

mglaman’s picture

bojanz’s picture

Status: Needs review » Needs work

Travis build failed:
https://travis-ci.org/drupalcommerce/commerce/jobs/162042536
Drupal\Core\Entity\Query\QueryException: 'cart' not found

mglaman’s picture

Status: Needs work » Needs review
StatusFileSize
new8.02 KB

Posted updated fix. Worked locally. There's a hack to install commerce_cart in kernel tests.

  • bojanz committed 1e2ad0b on 8.x-2.x authored by borisson_
    Issue #2575719 by borisson_, jbertoen, mglaman: Add a test for...
bojanz’s picture

Status: Needs review » Fixed

Cleaned up some more and added coverage for finalizeCart().

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.