Something went wrong. Try again.
My attempts at exercism.org
Something went wrong. Try again.
2.8 kB · 102 lines
PHP
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103<?php
use PHPUnit\Framework\TestCase;use PHPUnit\Framework\Attributes\TestDox;
class HighSchoolSweetheartTest extends TestCase{ public static function setUpBeforeClass(): void { require_once 'HighSchoolSweetheart.php'; }
/** * @task_id 1 */ #[TestDox('gets the first letter from a string')] public function testFirstLetter() { $sweetheart = new HighSchoolSweetheart(); $this->assertEquals('J', $sweetheart->firstLetter('Jane')); }
/** * @task_id 1 */ #[TestDox("getting the first letter doesn't change the case")] public function testFirstLetterDoesNotChangeCase() { $sweetheart = new HighSchoolSweetheart(); $this->assertEquals('j', $sweetheart->firstLetter('jane')); }
/** * @task_id 1 */ #[TestDox('getting the first letter removes whitespace from the name')] public function testFirstLetterRemovesWhitespace() { $sweetheart = new HighSchoolSweetheart(); $this->assertEquals('J', $sweetheart->firstLetter(' Jane')); }
/** * @task_id 2 */ #[TestDox('gets the first letter and appends a dot')] public function testCreatesInitial() { $sweetheart = new HighSchoolSweetheart(); $this->assertEquals('B.', $sweetheart->initial('Betty')); }
/** * @task_id 2 */ #[TestDox('creates an uppercase initial')] public function testCreatesUppercaseInitial() { $sweetheart = new HighSchoolSweetheart(); $this->assertEquals('J.', $sweetheart->initial('jim')); }
/** * @task_id 3 */ #[TestDox('creates a set of initials')] public function testCreatesInitials() { $sweetheart = new HighSchoolSweetheart(); $this->assertEquals('L. M.', $sweetheart->initials('Linda Miller')); }
/** * @task_id 4 */ #[TestDox('creates a set of initials, wrapped in a heart')] public function testPair() { $sweetheart = new HighSchoolSweetheart(); $expected = <<<EXPECTED_HEART ****** ****** ** ** ** ** ** ** ** ** ** * ** ** ** ** A. B. + C. D. ** ** ** ** ** ** ** ** ** ** ** ** ** *** * EXPECTED_HEART;
$this->assertEquals( $expected, $sweetheart->pair('Avery Bryant', 'Charlie Dixon') ); }}