<?php
declare(strict_types=1);
namespace Tests\git2;
use git2\git;
use git2\git_signature;
final class MailmapTest extends GitTestCase
{
public function testFromBuffer(): void
{
$this->assertOK(git::mailmap_from_buffer($mm, 'John Doe <john.doe@example.com>'));
$this->assertOK(git::mailmap_resolve($rName, $rEmail, $mm, 'John R. Doe', 'john.doe@example.com'));
$this->assertSame('John Doe', $rName);
$this->assertSame('john.doe@example.com', $rEmail);
}
public function testFromRepository(): void
{
git::repository_init($repo, $dir = $this->mkdir('from_repository'), false);
file_put_contents($dir . '/.mailmap', 'John Doe <john.doe@example.com>');
$this->assertOK(git::mailmap_from_repository($mm, $repo));
$this->assertOK(git::mailmap_resolve($rName, $rEmail, $mm, 'John R. Doe', 'john.doe@example.com'));
$this->assertSame('John Doe', $rName);
$this->assertSame('john.doe@example.com', $rEmail);
}
public function testResolveSignature(): void
{
git::mailmap_new($mm);
git::mailmap_add_entry($mm, 'John Doe', 'john.doe@example.com', null, 'john.doe@example.com');
git::signature_now($sig, 'john', 'john.doe@example.com');
$this->assertOK(git::mailmap_resolve_signature($res, $mm, $sig));
$this->assertInstanceOf(git_signature::class, $res);
$this->assertSame('John Doe', $res->name);
}
}