1.) As mentioned in the article above, I used the mock testGetRecordDetails() object to create a test that checks if the Cart properly interacts with the Record Loader. We want to make sure that the cart sends the correct values into the loader and returns whatever the loader sends back. We test the first part with an expects() condition in the mock, and we test the second part by configuring the mock to return a specific value and checking for that value with an ->assertEquals() assertion.

2.) There is one line of code in the cart class that we can’t test — the setcookie() line; it’s inherently untestable from the command-line environment. We’ll just have to live with that. Fortunately, PHPUnit allows annotation comments to exclude untestable lines from code coverage reports — by surrounding the offending code with // @codeCoverageIgnoreStart and // @codeCoverageIgnoreEnd we can mark the problem area.