Laravel Mock进行Unitari测试功能

问题描述

我是模拟的新手,我无法找出使用模拟/存根单一测试功能方法

这是我的测试,我要检查剪贴对象中的getCourse方法是否将返回我作为参数传递给函数的特定过程的数据。

    public function test_get_detailed_info_from_PHPcourse()
    {
        $PHPCourse = new Course('PHP');
        $result = $this->scrapy->getCourse($PHPCourse);

        $this->assertContains('PHP Tutorial',$result);
        $this->assertContains('100',$result);
        $this->assertContains('260 XP',$result);
    }

getCourse函数中的代码如下:

public function getCourse(Course $targetCourse)
    {
        $all_courses = $this->getAllCourses();
        foreach ($all_courses as $course){

            if (in_array ($targetCourse->getName(),$course)){
                return $course;
            }
        }
    }

我嘲笑了辅助函数getAllCourses(),该函数用于在getCourse()函数内部抓取所有课程。

$scrapper = $this->mock(SoloLearnScraping::class,function ($mock) {
            $allCourses = include 'tests/Unit/Mock_CoursesSoloLearn.PHP';
            $mock->shouldReceive('getAllCourses')->andReturns($allCourses);
        });

我的问题是:如何在给定PHP课程的情况下进行测试,getCourse()将返回来自PHP课程的数据,并在html课程中传递时输出html课程数据?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)