File tree Expand file tree Collapse file tree 5 files changed +86
-1
lines changed Expand file tree Collapse file tree 5 files changed +86
-1
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ Algumas delas são:
4747> nunca deve abrir uma classe e adicionar um novo recurso, você deverá estendê-la (Expansão e Fechado para alteração)
4848
4949- L: Liskov Substituition - As classes derivadas devem ser substituíveis por suas classes base, sem que resultem em erros.
50- > subtipos e tipo devem se complementar
50+ > subtipos e tipo(pais e filhos) devem se complementar
5151
5252- I: Interface Segregation - Muitas interfaces específicas são melhores do que uma interface única.
5353> sempre trabalhar com interface
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Solid \Html ;
4+
5+ class Attributes
6+ {
7+ private $ attributes ;
8+
9+ public function __construct (array $ attributes )
10+ {
11+ $ this ->attributes = $ attributes ;
12+ }
13+
14+ public function __toString () : string
15+ {
16+ $ result = [];
17+
18+ foreach ($ this ->attributes as $ key => $ value )
19+ {
20+ $ result [] = $ key . '=" ' . $ value . '" ' ;
21+ }
22+
23+ return ' ' . implode (' ' , $ result );
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Solid \Html ;
4+
5+ class Tags
6+ {
7+ public function img (string $ src )
8+ {
9+ return '<img src=" ' . $ src . '"> ' ;
10+ }
11+
12+ public function a (string $ href , string $ anchor )
13+ {
14+ return '<a href=" ' . $ href . '"> ' . $ anchor . '</a> ' ;
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Solid \Html ;
4+
5+ class AttributesTest extends \PHPUnit \Framework \TestCase
6+ {
7+
8+ public function testCriarAtributosHtmlParaTags ()
9+ {
10+ $ attributes = new Attributes ([
11+ "class " => "btn btn-default " ,
12+ "data-modal " => "#login " ,
13+ "id " => "login "
14+ ]
15+ );
16+
17+ $ this ->assertEquals (' class="btn btn-default" data-modal="#login" id="login" ' , $ attributes );
18+ }
19+
20+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Solid \Html ;
4+
5+ class TagsTest extends \PHPUnit \Framework \TestCase
6+ {
7+ public function testCriarTagImgComSrc ()
8+ {
9+ $ html = new Html ;
10+ $ img = $ html ->img ('img/photo.png ' );
11+
12+ $ this ->assertEquals ('<img src="img/photo.png"> ' , $ img );
13+ }
14+
15+ public function testCriarTagAComImgAncora ()
16+ {
17+ $ html = new Html ;
18+ $ img = $ html ->img ('img/photo.png ' );
19+
20+ $ a = $ html ->a ('http://www.example.com.br ' , $ img );
21+
22+ $ this ->assertEquals ('<a href="http://www.example.com.br"><img src="img/photo.png"></a> ' , $ a );
23+ }
24+ }
You can’t perform that action at this time.
0 commit comments