Answer the question
In order to leave comments, you need to log in
What's wrong with my PHP tests?
<?php
namespace Tasks\tests;
/*
require_once '../tasks/task3/Lesson.php';
require_once '../tasks/task3/Grammar.php';
require_once '../tasks/task3/Speaking.php';
require_once '../Tasks/task3/Strategy/CostStrategy.php';
require_once '../tasks/task3/Strategy/TimeStrategy.php';
require_once '../tasks/task3/Strategy/FixedStrategy.php';
*/
use Tasks\task3\Grammar;
use Tasks\task3\Speaking;
use Tasks\task3\Strategy\FixedStrategy;
use Tasks\task3\Strategy\TimeStrategy;
class TestLessons extends \PHPUnit_Framework_TestCase
{
public function testLessonsGrammarFixedCostGood()
{
for ($i = 0; $i < 2; $i++) {
$grammar = new Grammar(2, new FixedStrategy());
$this->assertEquals(600, $grammar->cost());
}
}
public function testLessonsSpeakingTimedCostGood()
{
for ($i = 0; $i < 2; $i++) {
$spaeking = new Speaking(3, new TimeStrategy());
$this->assertEquals(900, $spaeking->cost());
}
}
public function testLessonsGrammarTimedCostBad()
{
for ($i = 0; $i < 2; $i++) {
$grammar = new Grammar(3, new TimeStrategy());
$this->assertNotEquals(900, $grammar->cost());
}
}
}
Answer the question
In order to leave comments, you need to log in
Telepath mode:
1. Instead of use Tasks\task3\Grammar;
all the same, it’s more correct to write use \Tasks\task3\Grammar;
2. Show the beginning of the tasks/task3/Grammar.php file
3. As far as I remember, autoloading will not work without explicit --bootstrap - but since everything crashes and the problem is clearly with require_once not in this.
<?php
namespace Tasks\task3;
use Tasks\task3\Strategy\CostStrategy;
class Lesson
{
protected $duration;
protected $costStrategy;
public function __construct($duration, CostStrategy $strategy)
{
$this->duration = $duration;
$this->costStrategy = $strategy;
}
public function cost()
{
return $this->costStrategy->cost($this);
}
public function chargeType()
{
return $this->costStrategy->chargeType();
}
public function getDuration()
{
return $this->duration;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question