From 803b2eb9795ab01ad339a037c5b6eccf0ca6024c Mon Sep 17 00:00:00 2001 From: Len Woodward Date: Sat, 4 Jan 2025 01:45:05 -0800 Subject: [PATCH] add tests --- tests/Feature/DiffTest.php | 86 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tests/Feature/DiffTest.php diff --git a/tests/Feature/DiffTest.php b/tests/Feature/DiffTest.php new file mode 100644 index 00000000..76b1fcfc --- /dev/null +++ b/tests/Feature/DiffTest.php @@ -0,0 +1,86 @@ +shouldReceive('diff') + ->with('main') + ->once() + ->andReturn([ + base_path('tests/Fixtures/without-issues-laravel/file.php'), + ]); + + $this->swap(PathsRepository::class, $paths); + + [$statusCode, $output] = run('default', ['--diff' => 'main']); + + expect($statusCode)->toBe(0) + ->and($output) + ->toContain('── Laravel', ' 1 file'); +}); + +it('ignores the path argument', function () { + $paths = Mockery::mock(PathsRepository::class); + + $paths + ->shouldReceive('diff') + ->once() + ->andReturn([ + base_path('tests/Fixtures/without-issues-laravel/file.php'), + ]); + + $this->swap(PathsRepository::class, $paths); + + [$statusCode, $output] = run('default', [ + '--diff' => 'main', + 'path' => base_path(), + ]); + + expect($statusCode)->toBe(0) + ->and($output) + ->toContain('── Laravel', ' 1 file'); +}); + +it('does not abort when there are no diff files', function () { + $paths = Mockery::mock(PathsRepository::class); + + $paths + ->shouldReceive('diff') + ->once() + ->andReturn([]); + + $this->swap(PathsRepository::class, $paths); + + [$statusCode, $output] = run('default', [ + '--diff' => 'main', + ]); + + expect($statusCode)->toBe(0) + ->and($output) + ->toContain('── Laravel', ' 0 files'); +}); + +it('parses nested branch names', function () { + $paths = Mockery::mock(PathsRepository::class); + + $paths + ->shouldReceive('diff') + ->with('origin/main') + ->once() + ->andReturn([ + base_path('tests/Fixtures/without-issues-laravel/file.php'), + ]); + + $this->swap(PathsRepository::class, $paths); + + [$statusCode, $output] = run('default', [ + '--diff' => 'origin/main', + ]); + + expect($statusCode)->toBe(0) + ->and($output) + ->toContain('── Laravel', ' 1 file'); +});