The commit in #2749287: Implement a Calculator class and use it in the Price value object broke our tests. At first it just looked like it was due to tests passing floats or integers, instead of strings. But it is more than that.
There were 6 errors:
1) Drupal\Tests\commerce_order\Functional\OrderAdminTest::testCreateOrder
Behat\Mink\Exception\ElementNotFoundException: Button with id|name|label|value "Edit" not found.
/home/travis/build/drupalcommerce/drupal-8/drupal/core/tests/Drupal/Tests/WebAssert.php:76
/home/travis/build/drupalcommerce/drupal-8/drupal/core/tests/Drupal/Tests/BrowserTestBase.php:791
/home/travis/build/drupalcommerce/commerce/modules/order/tests/src/Functional/OrderAdminTest.php:66
2) Drupal\Tests\commerce_order\Kernel\AdjustmentItemTest::testAdjustmentItem
InvalidArgumentException: The provided value "-1" must be a string, not a float.
/home/travis/build/drupalcommerce/commerce/modules/price/src/Calculator.php:193
/home/travis/build/drupalcommerce/commerce/modules/price/src/Price.php:35
/home/travis/build/drupalcommerce/commerce/modules/order/tests/src/Kernel/AdjustmentItemTest.php:72
3) Drupal\Tests\commerce_order\Kernel\Entity\LineItemTest::testLineItem
InvalidArgumentException: The provided value "9.99" must be a string, not a float.
/home/travis/build/drupalcommerce/commerce/modules/price/src/Calculator.php:193
/home/travis/build/drupalcommerce/commerce/modules/price/src/Price.php:35
/home/travis/build/drupalcommerce/commerce/modules/order/tests/src/Kernel/Entity/LineItemTest.php:79
4) Drupal\Tests\commerce_order\Kernel\Entity\OrderTest::testOrder
InvalidArgumentException: The provided value "-1" must be a string, not a float.
/home/travis/build/drupalcommerce/commerce/modules/price/src/Calculator.php:193
/home/travis/build/drupalcommerce/commerce/modules/price/src/Price.php:35
/home/travis/build/drupalcommerce/commerce/modules/order/tests/src/Kernel/Entity/OrderTest.php:201
5) Drupal\Tests\commerce_order\Unit\AdjustmentTest::testValidAdjustmentConstruct
InvalidArgumentException: The provided value "-1" must be a string, not a float.
/home/travis/build/drupalcommerce/commerce/modules/price/src/Calculator.php:193
/home/travis/build/drupalcommerce/commerce/modules/price/src/Price.php:35
/home/travis/build/drupalcommerce/commerce/modules/order/tests/src/Unit/AdjustmentTest.php:64
/home/travis/build/drupalcommerce/drupal-8/drupal/vendor/phpunit/phpunit/phpunit:47
6) Drupal\Tests\commerce_order\Unit\AdjustmentTest::testAdjustmentMethods
InvalidArgumentException: The provided value "-1" must be a string, not a float.
/home/travis/build/drupalcommerce/commerce/modules/price/src/Calculator.php:193
/home/travis/build/drupalcommerce/commerce/modules/price/src/Price.php:35
/home/travis/build/drupalcommerce/commerce/modules/order/tests/src/Unit/AdjustmentTest.php:84
/home/travis/build/drupalcommerce/drupal-8/drupal/vendor/phpunit/phpunit/phpunit:47
FAILURES!
Tests: 146, Assertions: 1069, Errors: 6.
Comments
Comment #2
mglamanSomewhere along the time the
amountproperty in PriceItem becomes a non-string. I'm not sure where, even when applying the following diff we still get exceptions about the amount not being a string.The only viable fix seems to be ensuring that the PriceItem field casts the
amountproperty to string when constructing a new price object. This fixes tests (and is also a DX win)Comment #3
mglamanPR: https://github.com/drupalcommerce/commerce/pull/472 and patch
Comment #4
mglamanOne failure, on the order create form: Drupal\Tests\commerce_order\Functional\OrderAdminTest::testCreateOrder.
Comment #5
mglamanAlso, can't save or add line items in the UI
Comment #6
mglamanThere is also an issue on
\Drupal\commerce_order\Entity\OrderInterface::getTotalPricewhen the field is empty, it throws an error for calling toPrice on null.Comment #7
mglamanOrder UI is borked because of this. Made an adjustment and pushed
The error seems to be that the empty price field is non-numeric, so we need to convert it to a numeric value (empty string is zero.)
Comment #9
mglamanTests are now passing!