|
19 | 19 | use PHPUnit\Framework\Attributes\DataProvider; |
20 | 20 | use PHPUnit\Framework\Attributes\Test; |
21 | 21 | use PHPUnit\Framework\MockObject\MockObject; |
| 22 | +use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; |
| 23 | +use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException; |
22 | 24 |
|
23 | 25 | class ProjectsTest extends TestCase |
24 | 26 | { |
@@ -1600,6 +1602,186 @@ public function shouldDeleteDeployToken(): void |
1600 | 1602 | $this->assertEquals($expectedBool, $api->deleteDeployToken(1, 2)); |
1601 | 1603 | } |
1602 | 1604 |
|
| 1605 | + #[Test] |
| 1606 | + public function shouldGetPushRule(): void |
| 1607 | + { |
| 1608 | + $expectedArray = [ |
| 1609 | + 'id' => 1, |
| 1610 | + 'project_id' => 3, |
| 1611 | + 'commit_message_regex' => 'Fixes \\d+\\..*', |
| 1612 | + 'branch_name_regex' => 'feature\\/.*', |
| 1613 | + 'author_email_regex' => '@example.com$', |
| 1614 | + ]; |
| 1615 | + |
| 1616 | + $api = $this->getApiMock(); |
| 1617 | + $api->expects($this->once()) |
| 1618 | + ->method('get') |
| 1619 | + ->with('projects/3/push_rule') |
| 1620 | + ->willReturn($expectedArray); |
| 1621 | + |
| 1622 | + $this->assertEquals($expectedArray, $api->pushRule(3)); |
| 1623 | + } |
| 1624 | + |
| 1625 | + #[Test] |
| 1626 | + public function shouldGetUnsetPushRule(): void |
| 1627 | + { |
| 1628 | + $api = $this->getApiMock(); |
| 1629 | + $api->expects($this->once()) |
| 1630 | + ->method('get') |
| 1631 | + ->with('projects/3/push_rule') |
| 1632 | + ->willReturn('null'); |
| 1633 | + |
| 1634 | + $this->assertEquals('null', $api->pushRule(3)); |
| 1635 | + } |
| 1636 | + |
| 1637 | + #[Test] |
| 1638 | + public function shouldCreatePushRule(): void |
| 1639 | + { |
| 1640 | + $expectedBool = true; |
| 1641 | + $parameters = [ |
| 1642 | + 'commit_message_regex' => 'Fixes \\d+\\..*', |
| 1643 | + 'branch_name_regex' => 'feature\\/.*', |
| 1644 | + 'author_email_regex' => '@example.com$', |
| 1645 | + ]; |
| 1646 | + |
| 1647 | + $api = $this->getApiMock(); |
| 1648 | + $api->expects($this->once()) |
| 1649 | + ->method('post') |
| 1650 | + ->with('projects/3/push_rule', $parameters) |
| 1651 | + ->willReturn($expectedBool); |
| 1652 | + |
| 1653 | + $this->assertEquals($expectedBool, $api->createPushRule(3, $parameters)); |
| 1654 | + } |
| 1655 | + |
| 1656 | + #[Test] |
| 1657 | + public function shouldCreatePushRuleWithBooleanAndIntegerParameters(): void |
| 1658 | + { |
| 1659 | + $expectedBool = true; |
| 1660 | + $parameters = [ |
| 1661 | + 'deny_delete_tag' => false, |
| 1662 | + 'member_check' => true, |
| 1663 | + 'prevent_secrets' => true, |
| 1664 | + 'commit_committer_check' => false, |
| 1665 | + 'commit_committer_name_check' => true, |
| 1666 | + 'reject_unsigned_commits' => false, |
| 1667 | + 'reject_non_dco_commits' => true, |
| 1668 | + 'max_file_size' => 100, |
| 1669 | + ]; |
| 1670 | + |
| 1671 | + $api = $this->getApiMock(); |
| 1672 | + $api->expects($this->once()) |
| 1673 | + ->method('post') |
| 1674 | + ->with('projects/3/push_rule', $parameters) |
| 1675 | + ->willReturn($expectedBool); |
| 1676 | + |
| 1677 | + $this->assertEquals($expectedBool, $api->createPushRule(3, $parameters)); |
| 1678 | + } |
| 1679 | + |
| 1680 | + #[Test] |
| 1681 | + public function shouldUpdatePushRule(): void |
| 1682 | + { |
| 1683 | + $expectedBool = true; |
| 1684 | + $parameters = [ |
| 1685 | + 'commit_message_regex' => 'Fixes \\d+\\..*', |
| 1686 | + 'branch_name_regex' => 'feature\\/.*', |
| 1687 | + 'author_email_regex' => '@example.com$', |
| 1688 | + ]; |
| 1689 | + |
| 1690 | + $api = $this->getApiMock(); |
| 1691 | + $api->expects($this->once()) |
| 1692 | + ->method('put') |
| 1693 | + ->with('projects/3/push_rule', $parameters) |
| 1694 | + ->willReturn($expectedBool); |
| 1695 | + |
| 1696 | + $this->assertEquals($expectedBool, $api->updatePushRule(3, $parameters)); |
| 1697 | + } |
| 1698 | + |
| 1699 | + #[Test] |
| 1700 | + public function shouldUpdatePushRuleWithBooleanAndIntegerParameters(): void |
| 1701 | + { |
| 1702 | + $expectedBool = true; |
| 1703 | + $parameters = [ |
| 1704 | + 'deny_delete_tag' => true, |
| 1705 | + 'member_check' => false, |
| 1706 | + 'prevent_secrets' => false, |
| 1707 | + 'commit_committer_check' => true, |
| 1708 | + 'commit_committer_name_check' => false, |
| 1709 | + 'reject_unsigned_commits' => true, |
| 1710 | + 'reject_non_dco_commits' => false, |
| 1711 | + 'max_file_size' => 25, |
| 1712 | + ]; |
| 1713 | + |
| 1714 | + $api = $this->getApiMock(); |
| 1715 | + $api->expects($this->once()) |
| 1716 | + ->method('put') |
| 1717 | + ->with('projects/3/push_rule', $parameters) |
| 1718 | + ->willReturn($expectedBool); |
| 1719 | + |
| 1720 | + $this->assertEquals($expectedBool, $api->updatePushRule(3, $parameters)); |
| 1721 | + } |
| 1722 | + |
| 1723 | + #[Test] |
| 1724 | + public function shouldDeletePushRule(): void |
| 1725 | + { |
| 1726 | + $expectedBool = true; |
| 1727 | + |
| 1728 | + $api = $this->getApiMock(); |
| 1729 | + $api->expects($this->once()) |
| 1730 | + ->method('delete') |
| 1731 | + ->with('projects/3/push_rule') |
| 1732 | + ->willReturn($expectedBool); |
| 1733 | + |
| 1734 | + $this->assertEquals($expectedBool, $api->deletePushRule(3)); |
| 1735 | + } |
| 1736 | + |
| 1737 | + #[Test] |
| 1738 | + public function shouldRejectUndefinedParameterWhenCreatingPushRule(): void |
| 1739 | + { |
| 1740 | + $api = $this->getApiMock(); |
| 1741 | + $api->expects($this->never()) |
| 1742 | + ->method('post'); |
| 1743 | + |
| 1744 | + $this->expectException(UndefinedOptionsException::class); |
| 1745 | + |
| 1746 | + $api->createPushRule(3, ['unsupported_parameter' => true]); |
| 1747 | + } |
| 1748 | + |
| 1749 | + #[Test] |
| 1750 | + public function shouldRejectUndefinedParameterWhenUpdatingPushRule(): void |
| 1751 | + { |
| 1752 | + $api = $this->getApiMock(); |
| 1753 | + $api->expects($this->never()) |
| 1754 | + ->method('put'); |
| 1755 | + |
| 1756 | + $this->expectException(UndefinedOptionsException::class); |
| 1757 | + |
| 1758 | + $api->updatePushRule(3, ['unsupported_parameter' => true]); |
| 1759 | + } |
| 1760 | + |
| 1761 | + #[Test] |
| 1762 | + public function shouldRequireIntegerMaxFileSizeWhenCreatingPushRule(): void |
| 1763 | + { |
| 1764 | + $api = $this->getApiMock(); |
| 1765 | + $api->expects($this->never()) |
| 1766 | + ->method('post'); |
| 1767 | + |
| 1768 | + $this->expectException(InvalidOptionsException::class); |
| 1769 | + |
| 1770 | + $api->createPushRule(3, ['max_file_size' => '100']); |
| 1771 | + } |
| 1772 | + |
| 1773 | + #[Test] |
| 1774 | + public function shouldRequireIntegerMaxFileSizeWhenUpdatingPushRule(): void |
| 1775 | + { |
| 1776 | + $api = $this->getApiMock(); |
| 1777 | + $api->expects($this->never()) |
| 1778 | + ->method('put'); |
| 1779 | + |
| 1780 | + $this->expectException(InvalidOptionsException::class); |
| 1781 | + |
| 1782 | + $api->updatePushRule(3, ['max_file_size' => '100']); |
| 1783 | + } |
| 1784 | + |
1603 | 1785 | #[Test] |
1604 | 1786 | public function shouldGetEvents(): void |
1605 | 1787 | { |
|
0 commit comments