'PHP Unit Test Problem with automatically generating Variable

im writing UnitTests in my school at the moment.

I understood that it checks if the variable context has/uses "timestamp" and if the variable is not set or "false" then it sets exactly that for the variable "time".

Now I have to write a unittest that checks this. The problem is that as soon as I don't set a variable with $context I get an error, because you need the variable $context for the constructor.

Additionally I can't find a suitable method, I used AssertNotSame etc., but this doesn't set an automatic variable :(

I hope someone can help me with that. :/

public function __construct(LogLevel $level, string $message, array $context = [])
{
    $this->message = $message;
    $this->level = $level;
    $this->context = $context;
    // We cannot safely assume timestamp is any specific format
    if (!isset($this->context['timestamp'])) {
        $this->context['timestamp'] = time();
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source