ArgumentCountError: Too few arguments to function

Viewed 184

I am testing my model in isolation and keep getting this error. I thought perhaps it is my assert function but I want to check if what list I created a new instance with is the same as the list found. Here is my model:

class ArchiveShoppingListModel
{
    /**
     * @var string
     */
    private string $list;

    /**
     * ArchiveShoppingListModel constructor.
     *
     * @param string $list
     */
    public function __construct(string $list)
    {
        $this->list = $list;
    }

    /**
     * @return string
     */
    public function getList(): string
    {
        return $this->list;
    }
}

And here is my test:

class ArchiveShoppingListModelTest extends TestCase
{
    /**
     * @param string $list
     * @return void
     */
    public function test(string $list): void
    {
        $model = new ArchiveShoppingListModel('groceries');

        $this->assertSame($list, $model->getList());
    }
}
1 Answers

Why you make $list as a parameter in unit test? If you want to check by unit test you'd better use

public function test(): void
{
  $list = ....; // the list you expect
  $model = new ArchiveShoppingListModel('groceries');
  $this->assertSame($list, $model->getList());
}
Related