O código fonte da classe de teste está assim:
<?php
namespace WellingtonBarbosa\Projeto\Tests;
use WellingtonBarbosa\Projeto\Buscador;
use GuzzleHttp\ClientInterface;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use Symfony\Component\DomCrawler\Crawler;
class TestBuscadorDeCursos extends TestCase
{
private $httpClientMock;
private $url = 'url-teste';
protected function setUp(): void
{
$html = <<<FIM
<html>
<body>
<span class="card-curso__nome">Curso Teste 1</span>
<span class="card-curso__nome">Curso Teste 2</span>
<span class="card-curso__nome">Curso Teste 3</span>
</body>
</html>
FIM;
$stream = $this->createMock(StreamInterface::class);
$stream
->expects($this->once())
->method('__toString')
->willReturn($html);
$response = $this->createMock(ResponseInterface::class);
$response
->expects($this->once())
->method('getBody')
->willReturn($stream);
$httpClient = $this
->createMock(ClientInterface::class);
$httpClient
->expects($this->once())
->method('request')
->with('GET', $this->url)
->willReturn($response);
$this->httpClientMock = $httpClient;
}
public function testBuscadorDeveRetornarCursos()
{
$crawler = new Crawler();
$buscador = new Buscador($this->httpClientMock, $crawler);
$cursos = $buscador->buscar($this->url);
$this->assertCount(3, $cursos);
$this->assertEquals('Curso Teste 1', $cursos[0]);
$this->assertEquals('Curso Teste 2', $cursos[1]);
$this->assertEquals('Curso Teste 3', $cursos[2]);
}
}
Ao executar o comando: composer test, recebo a seguinte mensagem:
λ composer test
> phpunit tests\TestBuscadorDeCursos.php
PHPUnit 9.0.0 by Sebastian Bergmann and contributors.
F 1 / 1 (100%)
Time: 00:00.135, Memory: 6.00 MB
There was 1 failure:
1) WellingtonBarbosa\Projeto\Tests\TestBuscadorDeCursos::testBuscadorDeveRetornarCursos
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'Curso Teste 1'
+'Curso Teste 1\r\n
+'
C:\Users\Wellington Barbosa\Documents\Cursos Alura\buscador-cursos-alura\tests\TestBuscadorDeCursos.php:60
FAILURES!
Tests: 1, Assertions: 2, Failures: 1.
Script phpunit tests\TestBuscadorDeCursos.php handling the test event returned with error code 1
Alterei o Line Separator para LF, no entanto o erro persiste.