Align matcher tests with substring matching
This commit is contained in:
@@ -6,9 +6,6 @@ class TicketKeyReferenceMatcher
|
|||||||
{
|
{
|
||||||
public function matches(string $ticketKey, string $referenceName): bool
|
public function matches(string $ticketKey, string $referenceName): bool
|
||||||
{
|
{
|
||||||
return preg_match(
|
return str_contains(mb_strtolower($referenceName), mb_strtolower($ticketKey));
|
||||||
'/^'.preg_quote($ticketKey, '/').'(?=$|[-_\/])/i',
|
|
||||||
$referenceName,
|
|
||||||
) === 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ class TicketKeyReferenceMatcherTest extends TestCase
|
|||||||
use RefreshDatabase;
|
use RefreshDatabase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure a reference must start with the ticket key, regardless of case.
|
* Ensure a reference matches when it contains the ticket key, regardless of case.
|
||||||
*/
|
*/
|
||||||
public function test_matcher_accepts_ticket_key_prefixes_case_insensitively(): void
|
public function test_matcher_accepts_references_containing_the_ticket_key_case_insensitively(): void
|
||||||
{
|
{
|
||||||
$matcher = app(TicketKeyReferenceMatcher::class);
|
$matcher = app(TicketKeyReferenceMatcher::class);
|
||||||
|
|
||||||
@@ -22,16 +22,18 @@ class TicketKeyReferenceMatcherTest extends TestCase
|
|||||||
$this->assertTrue($matcher->matches('CORE-1', 'CORE-1_hotfix'));
|
$this->assertTrue($matcher->matches('CORE-1', 'CORE-1_hotfix'));
|
||||||
$this->assertTrue($matcher->matches('CORE-1', 'CORE-1'));
|
$this->assertTrue($matcher->matches('CORE-1', 'CORE-1'));
|
||||||
$this->assertTrue($matcher->matches('CORE-1', 'core-1-login-form'));
|
$this->assertTrue($matcher->matches('CORE-1', 'core-1-login-form'));
|
||||||
|
$this->assertTrue($matcher->matches('CORE-1', 'CORE-10-login-form'));
|
||||||
|
$this->assertTrue($matcher->matches('CORE-1', 'MY-CORE-1-login-form'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure similar or embedded ticket keys are not treated as matches.
|
* Ensure references without the ticket key are not treated as matches.
|
||||||
*/
|
*/
|
||||||
public function test_matcher_rejects_other_ticket_prefixes(): void
|
public function test_matcher_rejects_references_without_the_ticket_key(): void
|
||||||
{
|
{
|
||||||
$matcher = app(TicketKeyReferenceMatcher::class);
|
$matcher = app(TicketKeyReferenceMatcher::class);
|
||||||
|
|
||||||
$this->assertFalse($matcher->matches('CORE-1', 'CORE-10-login-form'));
|
$this->assertFalse($matcher->matches('CORE-1', 'CORE-2-login-form'));
|
||||||
$this->assertFalse($matcher->matches('CORE-1', 'MY-CORE-1-login-form'));
|
$this->assertFalse($matcher->matches('CORE-1', 'feature/auth-cleanup'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -338,18 +338,21 @@ class ProjectTicketControllerTest extends TestCase
|
|||||||
->component('projects/Ticket')
|
->component('projects/Ticket')
|
||||||
->where('suggestedBranchName', 'core-1-branch-detail-test')
|
->where('suggestedBranchName', 'core-1-branch-detail-test')
|
||||||
->where('repositoryBranches.0.repository_connection.repository_full_name', 'core-team/kanbangit')
|
->where('repositoryBranches.0.repository_connection.repository_full_name', 'core-team/kanbangit')
|
||||||
->has('repositoryBranches.0.branches', 2)
|
->has('repositoryBranches.0.branches', 3)
|
||||||
->where('repositoryBranches.0.branches.0.name', 'CORE-1-login-form')
|
->where('repositoryBranches.0.branches.0.name', 'CORE-1-login-form')
|
||||||
->where('repositoryBranches.0.branches.1.name', 'CORE-1/fix-oauth')
|
->where('repositoryBranches.0.branches.1.name', 'CORE-1/fix-oauth')
|
||||||
|
->where('repositoryBranches.0.branches.2.name', 'CORE-10-should-not-match')
|
||||||
->where('repositoryBranches.1.repository_connection.repository_full_name', 'other-team/mobile')
|
->where('repositoryBranches.1.repository_connection.repository_full_name', 'other-team/mobile')
|
||||||
->where('repositoryBranches.1.repository_connection.has_personal_access', false)
|
->where('repositoryBranches.1.repository_connection.has_personal_access', false)
|
||||||
->where('repositoryBranches.1.branches', [])
|
->where('repositoryBranches.1.branches', [])
|
||||||
->has('repositoryPullRequests.0.pull_requests', 2)
|
->has('repositoryPullRequests.0.pull_requests', 3)
|
||||||
->where('repositoryPullRequests.0.pull_requests.0.number', '42')
|
->where('repositoryPullRequests.0.pull_requests.0.number', '42')
|
||||||
->where('repositoryPullRequests.0.pull_requests.0.title', 'Add login form')
|
->where('repositoryPullRequests.0.pull_requests.0.title', 'Add login form')
|
||||||
->where('repositoryPullRequests.0.pull_requests.0.status', 'open')
|
->where('repositoryPullRequests.0.pull_requests.0.status', 'open')
|
||||||
->where('repositoryPullRequests.0.pull_requests.1.number', '43')
|
->where('repositoryPullRequests.0.pull_requests.1.number', '43')
|
||||||
->where('repositoryPullRequests.0.pull_requests.1.status', 'merged')
|
->where('repositoryPullRequests.0.pull_requests.1.status', 'merged')
|
||||||
|
->where('repositoryPullRequests.0.pull_requests.2.number', '99')
|
||||||
|
->where('repositoryPullRequests.0.pull_requests.2.status', 'open')
|
||||||
->where('repositoryPullRequests.1.repository_connection.repository_full_name', 'other-team/mobile')
|
->where('repositoryPullRequests.1.repository_connection.repository_full_name', 'other-team/mobile')
|
||||||
->where('repositoryPullRequests.1.repository_connection.has_personal_access', false)
|
->where('repositoryPullRequests.1.repository_connection.has_personal_access', false)
|
||||||
->where('repositoryPullRequests.1.pull_requests', []),
|
->where('repositoryPullRequests.1.pull_requests', []),
|
||||||
|
|||||||
Reference in New Issue
Block a user