Best Atoum code snippet using dot.testClass
DigraphPrinterTest.php
Source:DigraphPrinterTest.php
1<?php declare(strict_types=1);2/**3 * PHP version 8.04 *5 * This source file is subject to the license that is bundled with this package in the file LICENSE.6 */7namespace PhUml\Graphviz;8use PHPUnit\Framework\TestCase;9use PhUml\Fakes\WithDotLanguageAssertions;10use PhUml\Graphviz\Styles\DigraphStyle;11use PhUml\Graphviz\Styles\ThemeName;12use PhUml\Templates\TemplateEngine;13use PhUml\Templates\TemplateFailure;14use PhUml\TestBuilders\A;15use RuntimeException;16final class DigraphPrinterTest extends TestCase17{18 use WithDotLanguageAssertions;19 /** @test */20 function its_dot_language_representation_contains_an_id_and_basic_display_settings()21 {22 $digraph = new Digraph();23 $dotLanguage = $this->printer->toDot($digraph);24 $this->assertMatchesRegularExpression('/^digraph "([0-9a-f]){40}"/', $dotLanguage);25 $this->assertStringContainsString('splines = true;26overlap = false;27mindist = 0.6;', $dotLanguage);28 }29 /** @test */30 function it_builds_an_html_label_for_a_class_with_attributes()31 {32 $class = A::class('AClass')33 ->withAPublicAttribute('name')34 ->withAPrivateAttribute('age')35 ->withAProtectedAttribute('category', 'string')36 ->build();37 $digraph = new Digraph();38 $digraph->add([new Node($class)]);39 $dotLanguage = $this->printer->toDot($digraph);40 $this->assertStringContainsString(41 '<TABLE CELLSPACING="0" BORDER="0" ALIGN="LEFT"><TR><TD BORDER="1" ALIGN="CENTER" BGCOLOR="#fcaf3e"><B><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="12">AClass</FONT></B></TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#eeeeec"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">+name</FONT><BR ALIGN="LEFT"/><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">-age</FONT><BR ALIGN="LEFT"/><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">#category: string</FONT><BR ALIGN="LEFT"/></TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#eeeeec"> </TD></TR></TABLE>',42 $dotLanguage43 );44 }45 /** @test */46 function it_builds_an_html_label_for_a_class_with_constants()47 {48 $class = A::class('AClass')49 ->withAConstant('NUMERIC', 'int')50 ->withAConstant('NO_TYPE')51 ->build();52 $digraph = new Digraph();53 $digraph->add([new Node($class)]);54 $dotLanguage = $this->printer->toDot($digraph);55 $this->assertStringContainsString(56 '<TABLE CELLSPACING="0" BORDER="0" ALIGN="LEFT"><TR><TD BORDER="1" ALIGN="CENTER" BGCOLOR="#fcaf3e"><B><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="12">AClass</FONT></B></TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#eeeeec"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10"><I>+NUMERIC: int</I></FONT><BR ALIGN="LEFT"/><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10"><I>+NO_TYPE</I></FONT><BR ALIGN="LEFT"/></TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#eeeeec"> </TD></TR></TABLE>',57 $dotLanguage58 );59 }60 /** @test */61 function it_builds_an_html_label_for_a_class_with_constants_attributes_and_methods()62 {63 $class = A::class('AClass')64 ->withAPrivateAttribute('age')65 ->withAProtectedAttribute('category', 'string')66 ->withAPublicMethod('getAge')67 ->withAProtectedMethod(68 'setCategory',69 A::parameter('category')->withType('string')->build()70 )71 ->withAConstant('NUMERIC', 'int')72 ->build();73 $digraph = new Digraph();74 $digraph->add([new Node($class)]);75 $dotLanguage = $this->printer->toDot($digraph);76 $this->assertStringContainsString(77 '<TABLE CELLSPACING="0" BORDER="0" ALIGN="LEFT"><TR><TD BORDER="1" ALIGN="CENTER" BGCOLOR="#fcaf3e"><B><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="12">AClass</FONT></B></TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#eeeeec"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10"><I>+NUMERIC: int</I></FONT><BR ALIGN="LEFT"/><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">-age</FONT><BR ALIGN="LEFT"/><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">#category: string</FONT><BR ALIGN="LEFT"/></TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#eeeeec"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">+getAge()</FONT><BR ALIGN="LEFT"/><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">#setCategory(category: string)</FONT><BR ALIGN="LEFT"/></TD></TR></TABLE>',78 $dotLanguage79 );80 }81 /** @test */82 function it_builds_an_html_label_for_an_interface()83 {84 $interface = A::interfaceNamed('AnInterface');85 $digraph = new Digraph();86 $digraph->add([new Node($interface)]);87 $dotLanguage = $this->printer->toDot($digraph);88 $this->assertStringContainsString(89 '<TABLE CELLSPACING="0" BORDER="0" ALIGN="LEFT"><TR><TD BORDER="1" ALIGN="CENTER" BGCOLOR="#fcaf3e"><B><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="12"><I>AnInterface</I></FONT></B></TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#eeeeec"> </TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#eeeeec"> </TD></TR></TABLE>',90 $dotLanguage91 );92 }93 /** @test */94 function it_builds_an_html_label_for_an_interface_with_methods_and_constants()95 {96 $interface = A::interface('AnInterface')97 ->withAPublicMethod('doSomething')98 ->withAPublicMethod('changeValue', A::parameter('$value')->withType('int')->build())99 ->withAConstant('NUMERIC', 'int')100 ->withAConstant('NO_TYPE')101 ->build();102 $digraph = new Digraph();103 $digraph->add([new Node($interface)]);104 $dotLanguage = $this->printer->toDot($digraph);105 $this->assertStringContainsString(106 '<TABLE CELLSPACING="0" BORDER="0" ALIGN="LEFT"><TR><TD BORDER="1" ALIGN="CENTER" BGCOLOR="#fcaf3e"><B><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="12"><I>AnInterface</I></FONT></B></TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#eeeeec"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10"><I>+NUMERIC: int</I></FONT><BR ALIGN="LEFT"/><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10"><I>+NO_TYPE</I></FONT><BR ALIGN="LEFT"/></TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#eeeeec"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">+doSomething()</FONT><BR ALIGN="LEFT"/><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">+changeValue($value: int)</FONT><BR ALIGN="LEFT"/></TD></TR></TABLE>',107 $dotLanguage108 );109 }110 /** @test */111 function it_builds_an_html_label_for_a_trait_with_attributes_and_methods()112 {113 $trait = A::trait('ATrait')114 ->withAPrivateAttribute('age')115 ->withAProtectedAttribute('category', 'string')116 ->withAPublicMethod('getAge')117 ->withAProtectedMethod(118 'setCategory',119 A::parameter('category')->withType('string')->build()120 )121 ->withAMethod(A::method('count')->protected()->static()->build())122 ->withAMethod(A::method('display')->private()->abstract()->build())123 ->build();124 $digraph = new Digraph();125 $digraph->add([new Node($trait)]);126 $dotLanguage = $this->printer->toDot($digraph);127 $this->assertStringContainsString(128 '<TABLE CELLSPACING="0" BORDER="0" ALIGN="LEFT"><TR><TD BORDER="1" ALIGN="CENTER" BGCOLOR="#fcaf3e"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10"><<trait>></FONT><BR/><B><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="12"><I>ATrait</I></FONT></B></TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#eeeeec"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">-age</FONT><BR ALIGN="LEFT"/><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">#category: string</FONT><BR ALIGN="LEFT"/></TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#eeeeec"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">+getAge()</FONT><BR ALIGN="LEFT"/><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">#setCategory(category: string)</FONT><BR ALIGN="LEFT"/><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10"><U>#count()</U></FONT><BR ALIGN="LEFT"/><I><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">-display()</FONT></I><BR ALIGN="LEFT"/></TD></TR></TABLE>',129 $dotLanguage130 );131 }132 /** @test */133 function it_represents_a_single_definition_as_dot_language()134 {135 $class = A::classNamed('TestClass');136 $digraph = new Digraph();137 $digraph->add([new Node($class)]);138 $dotLanguage = $this->printer->toDot($digraph);139 $this->assertNode($class, $dotLanguage);140 }141 /** @test */142 function it_represents_inheritance_as_dot_language()143 {144 $parentClass = A::classNamed('ParentClass');145 $class = A::class('TestClass')->extending($parentClass->name())->build();146 $digraph = new Digraph();147 $digraph->add([148 new Node($parentClass),149 new Node($class),150 Edge::inheritance($parentClass, $class),151 ]);152 $dotLanguage = $this->printer->toDot($digraph);153 $this->assertNode($parentClass, $dotLanguage);154 $this->assertNode($class, $dotLanguage);155 $this->assertInheritance($class, $parentClass, $dotLanguage);156 }157 /** @test */158 function it_represents_a_class_using_a_trait_as_dot_language()159 {160 $trait = A::traitNamed('ATrait');161 $class = A::class('TestClass')->extending($trait->name())->build();162 $digraph = new Digraph();163 $digraph->add([164 new Node($trait),165 new Node($class),166 Edge::use($trait, $class),167 ]);168 $dotLanguage = $this->printer->toDot($digraph);169 $this->assertNode($trait, $dotLanguage);170 $this->assertNode($class, $dotLanguage);171 $this->assertUseTrait($class, $trait, $dotLanguage);172 }173 /** @test */174 function it_represents_interfaces_implementations_as_dot_language()175 {176 $anInterface = A::interfaceNamed('AnInterface');177 $anotherInterface = A::interfaceNamed('AnotherInterface');178 $class = A::class('TestClass')179 ->implementing($anInterface->name(), $anotherInterface->name())180 ->build();181 $digraph = new Digraph();182 $digraph->add([183 new Node($class),184 Edge::implementation($anInterface, $class),185 Edge::implementation($anotherInterface, $class),186 new Node($anInterface),187 new Node($anotherInterface),188 ]);189 $dotLanguage = $this->printer->toDot($digraph);190 $this->assertNode($class, $dotLanguage);191 $this->assertNode($anInterface, $dotLanguage);192 $this->assertNode($anotherInterface, $dotLanguage);193 $this->assertImplementation($class, $anInterface, $dotLanguage);194 $this->assertImplementation($class, $anotherInterface, $dotLanguage);195 }196 /** @test */197 function it_represents_constructor_dependencies_as_associations_in_dot_language()198 {199 $reference = A::classNamed('AReference');200 $class = A::class('TestClass')201 ->withAPublicMethod(202 '__construct',203 A::parameter('$aReference')->withType('AReference')->build()204 )205 ->build();206 $digraph = new Digraph();207 $digraph->add([208 new Node($reference),209 Edge::association($reference, $class),210 new Node($class),211 ]);212 $dotLanguage = $this->printer->toDot($digraph);213 $this->assertNode($reference, $dotLanguage);214 $this->assertNode($class, $dotLanguage);215 $this->assertAssociation($reference, $class, $dotLanguage);216 }217 /** @test */218 function it_represents_class_attributes_as_associations_in_dot_language()219 {220 $reference = A::classNamed('AReference');221 $class = A::class('TestClass')222 ->withAPrivateAttribute('$aReference', 'AReference')223 ->build()224 ;225 $digraph = new Digraph();226 $digraph->add([227 new Node($reference),228 Edge::association($reference, $class),229 new Node($class),230 ]);231 $dotLanguage = $this->printer->toDot($digraph);232 $this->assertNode($reference, $dotLanguage);233 $this->assertNode($class, $dotLanguage);234 $this->assertAssociation($reference, $class, $dotLanguage);235 }236 /** @test */237 function it_fails_to_build_a_label_if_twig_fails()238 {239 $templateEngine = new class() extends TemplateEngine {240 public function render(string $template, array $context = []): string241 {242 throw new TemplateFailure(new RuntimeException('Twig runtime error'));243 }244 };245 $printer = new DigraphPrinter($templateEngine, DigraphStyle::default(new ThemeName('phuml')));246 $this->expectException(TemplateFailure::class);247 $this->expectExceptionMessage('Template rendering failed: Twig runtime error');248 $printer->toDot(new Digraph());249 }250 /** @before */251 function let()252 {253 $this->printer = new DigraphPrinter(new TemplateEngine(), DigraphStyle::default(new ThemeName('phuml')));254 }255 private DigraphPrinter $printer;256}...
FilesystemTest.php
Source:FilesystemTest.php
1<?php2namespace Tests;3use App\TestClass;4use Orchestra\Testbench\TestCase;5use Illuminate\Support\Facades\File;6use const DIRECTORY_SEPARATOR as DS;7class FilesystemTest extends TestCase8{9 protected function setUp() : void10 {11 $this->afterApplicationCreated(static function () {12 $class = app_path('TestClass.php');13 if (! File::exists($class)) {14 File::replace($class, <<<EOT15<?php 16namespace App; 17class TestClass18{19 public function something()20 {21 // ...22 }23 24 protected function privateFunction(int \$argument, User \$user, string \$optional = null)25 {26 27 }28} 29EOT30 );31 }32 require_once $class;33 });34 parent::setUp();35 }36 public function test_base_path_of()37 {38 $this->assertSame('app' . DS . 'TestClass.php', base_path_of(new TestClass()));39 $this->assertSame('app' . DS . 'TestClass.php', base_path_of(TestClass::class));40 }41 public function test_class_defined_at()42 {43 $this->assertSame(base_path('app' . DS . 'TestClass.php') . ':5', class_defined_at(TestClass::class));44 $this->assertSame(base_path('app' . DS . 'TestClass.php'), class_defined_at(TestClass::class, false));45 $this->assertSame(base_path('app' . DS . 'TestClass.php') . ':5', class_defined_at(new TestClass()));46 $this->assertSame(base_path('app' . DS . 'TestClass.php'), class_defined_at(new TestClass(), false));47 }48 public function test_dot_path()49 {50 $this->assertSame('foo.Bar.quz', dot_path('\foo\Bar/quz'));51 $this->assertSame('foo.Bar.quz', dot_path('foo\Bar/quz'));52 }53 public function test_undot_path()54 {55 $this->assertSame('foo' . DS . 'Bar' . DS . 'quz', undot_path('foo.Bar.quz'));56 $this->assertSame('foo' . DS . 'Bar' . DS . 'quz', undot_path('foo.Bar.quz'));57 }58}...
testClass
Using AI Code Generation
1require_once 'dot.class.php';2$dot = new dot();3echo $dot->testClass();4require_once 'dot.class.php';5$dot = new dot();6echo $dot->testClass();7require_once 'dot.class.php';8$dot = new dot();9echo $dot->testClass();10require_once 'dot.class.php';11$dot = new dot();12echo $dot->testClass();13require_once 'dot.class.php';14$dot = new dot();15echo $dot->testClass();16require_once 'dot.class.php';17$dot = new dot();18echo $dot->testClass();19require_once 'dot.class.php';20$dot = new dot();21echo $dot->testClass();22require_once 'dot.class.php';23$dot = new dot();24echo $dot->testClass();25require_once 'dot.class.php';26$dot = new dot();27echo $dot->testClass();28require_once 'dot.class.php';29$dot = new dot();30echo $dot->testClass();31require_once 'dot.class.php';32$dot = new dot();33echo $dot->testClass();34require_once 'dot.class.php';35$dot = new dot();36echo $dot->testClass();37require_once 'dot.class.php';38$dot = new dot();39echo $dot->testClass();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with testClass on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!