Laravel 5.5。无法使用特定名称实例化 class
Laravel 5.5. Can't instantiate class with a specific name
我有 2 个 类:\App\Services\WeatherService
和 \App\Services\WeatherService1
都相等。
在我的 \Tests\Unit\Services\WeatherServiceTest
中,我正在尝试创建一个新实例,但我无法实例化 \App\Services\WeatherService
。
//Works perfect
$some = new WeatherService1(new \Forecast\Forecast(config('darksky.key')));
dd($some);
/*
App\Services\WeatherService1 {#2405
-forecastApi: Forecast\Forecast {#2406
-api_key: "somekey"
}
}
*/
原始天气服务提供
//Not working
$some = new WeatherService(new \Forecast\Forecast(config('darksky.key')));
dd($some); //app\Services\WeatherService {#2405}
如何解决这个问题?
在另一个测试中我有这样一个 use
语句。
use app\Services\WeatherService;
改为
use App\Services\WeatherService;
已解决问题。
这里是class的代码。也许,某人知道为什么会这样。但是很奇怪。
class WeatherControllerTest extends TestCase
{
use WithoutMiddleware;
private $mock;
private $cities;
protected function setUp()
{
parent::setUp();
$this->mock = \Mockery::mock(WeatherService::class);
}
public function tearDown()
{
\Mockery::close();
}
//...
}
我有 2 个 类:\App\Services\WeatherService
和 \App\Services\WeatherService1
都相等。
在我的 \Tests\Unit\Services\WeatherServiceTest
中,我正在尝试创建一个新实例,但我无法实例化 \App\Services\WeatherService
。
//Works perfect
$some = new WeatherService1(new \Forecast\Forecast(config('darksky.key')));
dd($some);
/*
App\Services\WeatherService1 {#2405
-forecastApi: Forecast\Forecast {#2406
-api_key: "somekey"
}
}
*/
原始天气服务提供
//Not working
$some = new WeatherService(new \Forecast\Forecast(config('darksky.key')));
dd($some); //app\Services\WeatherService {#2405}
如何解决这个问题?
在另一个测试中我有这样一个 use
语句。
use app\Services\WeatherService;
改为
use App\Services\WeatherService;
已解决问题。
这里是class的代码。也许,某人知道为什么会这样。但是很奇怪。
class WeatherControllerTest extends TestCase
{
use WithoutMiddleware;
private $mock;
private $cities;
protected function setUp()
{
parent::setUp();
$this->mock = \Mockery::mock(WeatherService::class);
}
public function tearDown()
{
\Mockery::close();
}
//...
}