How to mock/spy/fake a non existing class in unit tests?
I have a task to create a webshop basket for example. Call it Basket class. This Basket has many relations for shipping address, billing address, products, consts, discounts, etc.
When I create this Basket class the other related classes doesn't exists yet.
How can I unit test the Basket class without related classes, if I want to test relations too?
@netdjw this all feels very spell-checking. Personally, I would drive this out in feature tests - very quickly if the relationship is not present and correct, the tests will fail. If you must...
$model = new Model; // your class under test
$relation = $model->related(); // use relationship function
$related = $relation->getRelated();
$this->assertInstanceOf(HasMany::class, $relation);
$this->assertInstanceOf(Other::class, $related);
A HasMany always returns a Colleection, so we're not testing that
@netdjw you're asking the test to make an assertion that a relationship should return a Collection of fictional/not-yet-implemented classes; is this correct?
@netdjw I would test only what the system is or should do, not anticipating code I will write in the future. Whenever you implement Other and define the relationship, then add those Test Examples.