How to use testClass method of phpClass class

Best Atoum code snippet using phpClass.testClass

PhpFileContentBuilderTest.php

Source:PhpFileContentBuilderTest.php Github

copy

Full Screen

1<?php2/*3 *4 * This file is part of leprz/boilerplate-generator5 *6 * Copyright (c) 2021. Przemek Łęczycki <leczycki.przemyslaw@gmail.com>7 */8declare(strict_types=1);9namespace Leprz\Boilerplate\Tests\Builder;10use Leprz\Boilerplate\Builder\PhpClassMetadataBuilder;11use Leprz\Boilerplate\Builder\PhpFileContentBuilder;12use Leprz\Boilerplate\PathNode\Folder;13use Leprz\Boilerplate\PathNode\Php\Call\PhpArgument;14use Leprz\Boilerplate\PathNode\Php\Call\PhpAttributeCall;15use Leprz\Boilerplate\PathNode\Php\PhpAttribute;16use Leprz\Boilerplate\PathNode\Php\PhpClass;17use Leprz\Boilerplate\PathNode\Php\PhpFile;18use Leprz\Boilerplate\PathNode\Php\PhpInterface;19use Leprz\Boilerplate\PathNode\Php\PhpMethod;20use Leprz\Boilerplate\PathNode\Php\PhpParameter;21use Leprz\Boilerplate\PathNode\Php\PhpTrait;22use Leprz\Boilerplate\PathNode\Php\PhpType;23use Leprz\Boilerplate\Tests\UnitTestCase;24/**25 * @covers \Leprz\Boilerplate\Builder\PhpFileContentBuilder26 * @uses \Leprz\Boilerplate\Builder\PhpClassMetadataBuilder27 * @uses \Leprz\Boilerplate\PathNode\File28 * @uses \Leprz\Boilerplate\PathNode\PathNode29 * @uses \Leprz\Boilerplate\PathNode\Php\PhpClass30 * @uses \Leprz\Boilerplate\PathNode\Php\PhpFile31 * @uses \Leprz\Boilerplate\PathNode\Php\PhpMethod32 * @uses \Leprz\Boilerplate\PathNode\Php\PhpType33 * @uses \Leprz\Boilerplate\PathNode\Php\PhpInterface34 * @uses \Leprz\Boilerplate\PathNode\Php\PhpParameter35 * @uses \Leprz\Boilerplate\PathNode\Folder36 */37class PhpFileContentBuilderTest extends UnitTestCase38{39 private const APP_PREFIX = 'App';40 /**41 * @var \Leprz\Boilerplate\Builder\PhpFileContentBuilder42 */43 private PhpFileContentBuilder $phpFileContentBuilder;44 public function test_build_should_buildPhpFileContent()45 {46 $phpFileContent = $this->phpFileContentBuilder->build(new PhpFile('Test'));47 $this->assertStringContainsString('<?', $phpFileContent);48 $this->assertStringContainsString('declare(strict_types=1);', $phpFileContent);49 }50 public function test_build_should_buildPhpClassContent()51 {52 $phpFileContent = $this->phpFileContentBuilder->build(new PhpClass('TestClass'));53 $this->assertStringContainsString('<?', $phpFileContent);54 $this->assertStringContainsString('declare(strict_types=1);', $phpFileContent);55 $this->assertStringContainsString('namespace ' . self::APP_PREFIX, $phpFileContent);56 $this->assertStringContainsString('class TestClass', $phpFileContent);57 }58 public function test_build_should_buildClassMethod()59 {60 $phpFileContent = $this->phpFileContentBuilder->build(61 (new PhpClass('TestClass'))62 ->addMethod(new PhpMethod('test', 'public', PhpType::string()))63 );64 $this->assertStringContainsString(65 'public function test(): string{}',66 preg_replace('/(\n|\s{4})/', '', $phpFileContent)67 );68 }69 public function test_build_should_buildClassMethodWithNoReturnType()70 {71 $phpFileContent = $this->phpFileContentBuilder->build(72 (new PhpClass('TestClass'))73 ->addMethod(new PhpMethod('test', 'public', null))74 );75 $this->assertStringNotContainsString(76 '@return',77 preg_replace('/(\n|\s{4})/', '', $phpFileContent)78 );79 $this->assertStringContainsString(80 'public function test(){}',81 preg_replace('/(\n|\s{4})/', '', $phpFileContent)82 );83 }84 public function test_build_should_buildClassMethodWithSimpleReturnType()85 {86 $phpFileContent = $this->phpFileContentBuilder->build(87 (new PhpClass('TestClass'))88 ->addMethod(new PhpMethod('test', 'public', PhpType::string()))89 );90 $this->assertStringContainsString(91 '@return string',92 preg_replace('/(\n|\s{4})/', '', $phpFileContent)93 );94 $this->assertStringContainsString(95 'public function test(): string{}',96 preg_replace('/(\n|\s{4})/', '', $phpFileContent)97 );98 }99 public function test_build_should_buildClassMethodWithObjectReturnType()100 {101 $returnType = (new Folder('Test'))102 ->addPhpClass(new PhpClass('ReturnTypeClass'));103 // TODO Test/TestClass returned in TestClass will not figure out alias. Create possibility to add alias104 $phpFileContent = $this->phpFileContentBuilder->build(105 (new PhpClass('TestClass'))106 ->addMethod(new PhpMethod('test', 'public', PhpType::object($returnType)))107 );108 $this->assertStringContainsString(109 sprintf('use %s\Test\ReturnTypeClass;', self::APP_PREFIX),110 $phpFileContent111 );112 $this->assertStringContainsString(113 sprintf('@return \%s\Test\ReturnTypeClass', self::APP_PREFIX),114 preg_replace('/(\n|\s{4})/', '', $phpFileContent)115 );116 $this->assertStringContainsString(117 'public function test(): ReturnTypeClass{}',118 preg_replace('/(\n|\s{4})/', '', $phpFileContent)119 );120 }121 public function test_build_should_buildClassMethodWithArraySimpleReturnType()122 {123 $phpFileContent = $this->phpFileContentBuilder->build(124 (new PhpClass('TestClass'))125 ->addMethod(new PhpMethod('test', 'public', PhpType::array()))126 );127 $this->assertStringContainsString(128 '@return array',129 preg_replace('/(\n|\s{4})/', '', $phpFileContent)130 );131 $this->assertStringContainsString(132 'public function test(): array{}',133 preg_replace('/(\n|\s{4})/', '', $phpFileContent)134 );135 }136 public function test_build_should_buildClassMethodWithArrayOfObjectsReturnType()137 {138 $returnType = (new Folder('Test'))139 ->addPhpClass(new PhpClass('ReturnTypeClass'));140 // TODO Test/TestClass returned in TestClass will not figure out alias. Create possibility to add alias141 $phpFileContent = $this->phpFileContentBuilder->build(142 (new PhpClass('TestClass'))143 ->addMethod(new PhpMethod('test', 'public', PhpType::array($returnType)))144 );145 $this->assertStringContainsString(146 '@return \App\Test\ReturnTypeClass[]',147 preg_replace('/(\n|\s{4})/', '', $phpFileContent)148 );149 $this->assertStringContainsString(150 'public function test(): array{}',151 preg_replace('/(\n|\s{4})/', '', $phpFileContent)152 );153 $this->assertStringContainsString(154 'use App\Test\ReturnTypeClass;',155 $phpFileContent156 );157 }158 public function test_build_should_buildMethodWithFinalAndStaticVisibility()159 {160 $phpFileContent = $this->phpFileContentBuilder->build(161 (new PhpClass('TestClass'))162 ->addMethod(163 new PhpMethod(164 'test',165 'final static public',166 null,167 )168 )169 );170 $this->assertStringContainsString(171 'final public static function test',172 $phpFileContent173 );174 }175 public function test_build_should_buildMethodParameterWithNoType()176 {177 $phpFileContent = $this->phpFileContentBuilder->build(178 (new PhpClass('TestClass'))179 ->addMethod(180 new PhpMethod(181 'test',182 'public',183 null,184 [185 new PhpParameter('test')186 ]187 )188 )189 );190 $this->assertStringNotContainsString(191 '@param',192 $phpFileContent193 );194 $this->assertStringContainsString(195 'test($test)',196 $phpFileContent197 );198 }199 public function test_build_should_buildMethodParameterWithSimpleType()200 {201 $phpFileContent = $this->phpFileContentBuilder->build(202 (new PhpClass('TestClass'))203 ->addMethod(204 new PhpMethod(205 'test',206 'public',207 null,208 [209 new PhpParameter('test', PhpType::string())210 ]211 )212 )213 );214 $this->assertStringContainsString(215 '@param string',216 $phpFileContent217 );218 $this->assertStringContainsString(219 'test(string $test)',220 $phpFileContent221 );222 }223 public function test_build_should_buildMethodParameterWithSimpleObject()224 {225 $phpFileContent = $this->phpFileContentBuilder->build(226 (new PhpClass('TestClass'))227 ->addMethod(228 new PhpMethod(229 'test',230 'public',231 PhpType::string(),232 [233 new PhpParameter('test', PhpType::object())234 ]235 )236 )237 );238 $this->assertStringContainsString(239 'test(object $test)',240 $phpFileContent241 );242 $this->assertStringContainsString(243 '@param object',244 $phpFileContent245 );246 }247 public function test_build_should_buildMethodParameterWithObjectOfType()248 {249 $phpFileContent = $this->phpFileContentBuilder->build(250 (new PhpClass('TestClass'))251 ->addMethod(252 new PhpMethod(253 'test',254 'public',255 PhpType::string(),256 [257 new PhpParameter(258 'test',259 PhpType::object(260 (new Folder('Test'))->addPhpClass(new PhpClass('ParameterType'))261 )262 )263 ]264 )265 )266 );267 $this->assertStringContainsString(268 sprintf('use %s\Test\ParameterType;', self::APP_PREFIX),269 $phpFileContent270 );271 $this->assertStringContainsString(272 sprintf('@param \%s\Test\ParameterType', self::APP_PREFIX),273 $phpFileContent274 );275 $this->assertStringContainsString(276 'test(ParameterType $test)',277 $phpFileContent278 );279 }280 public function test_build_should_buildMethodParameterWithSimpleArrayOfType()281 {282 $phpFileContent = $this->phpFileContentBuilder->build(283 (new PhpClass('TestClass'))284 ->addMethod(285 new PhpMethod(286 'test',287 'public',288 PhpType::string(),289 [290 new PhpParameter(291 'test',292 PhpType::array()293 )294 ]295 )296 )297 );298 $this->assertStringContainsString(299 '@param array',300 $phpFileContent301 );302 $this->assertStringContainsString(303 'test(array $test)',304 $phpFileContent305 );306 }307 public function test_build_should_buildMethodParameterWithSimpleArrayType()308 {309 $ofType = (new Folder('Test'))310 ->addPhpClass(new PhpClass('ArrayTypeClass'));311 $phpFileContent = $this->phpFileContentBuilder->build(312 (new PhpClass('TestClass'))313 ->addMethod(314 new PhpMethod(315 'test',316 'public',317 PhpType::string(),318 [319 new PhpParameter(320 'test',321 PhpType::array($ofType)322 )323 ]324 )325 )326 );327 $this->assertStringContainsString(328 sprintf('@param \%s\Test\ArrayTypeClass[]', self::APP_PREFIX),329 $phpFileContent330 );331 $this->assertStringContainsString(332 'test(array $test)',333 $phpFileContent334 );335 }336 public function test_build_should_buildPhpClassAttributes()337 {338 $attributeFQCN = sprintf('%s\Test\TestAttribute', self::APP_PREFIX);339 $phpFileContent = $this->phpFileContentBuilder->build(340 (new PhpClass('TestClass'))341 ->addAttribute(342 (new PhpAttributeCall(PhpAttribute::fromFQCN($attributeFQCN)))343 ->addArgument(new PhpArgument('name'))344 ->addArgument(PhpArgument::const('\\Test\\TestNamespace', 'SOME_CONST'))345 ->addArgument(new PhpArgument('The name', 'named'))346 )347 );348 $this->assertStringContainsString(349 sprintf('use %s;', $attributeFQCN),350 $phpFileContent351 );352 $this->assertStringContainsString(353 sprintf('use %s;', 'Test\\TestNamespace'),354 $phpFileContent355 );356 $this->assertStringContainsString(357 "#[TestAttribute('name', TestNamespace::SOME_CONST, named: 'The name')]",358 $phpFileContent359 );360 }361 public function test_build_should_buildPhpInterfaceContent()362 {363 $phpFileContent = $this->phpFileContentBuilder->build(new PhpInterface('TestInterface'));364 $this->assertStringContainsString('<?', $phpFileContent);365 $this->assertStringContainsString('declare(strict_types=1);', $phpFileContent);366 $this->assertStringContainsString('namespace ' . self::APP_PREFIX, $phpFileContent);367 $this->assertStringContainsString('interface TestInterface', $phpFileContent);368 }369 public function test_build_should_buildInterfaceMethod()370 {371 $phpFileContent = $this->phpFileContentBuilder->build(372 (new PhpInterface('TestInterface'))373 ->addMethod(new PhpMethod('test', 'public', PhpType::string()))374 );375 $this->assertStringContainsString('public function test(): string;', $phpFileContent);376 }377 public function test_build_should_buildClassThatImplementsInterface()378 {379 $phpFileContent = $this->phpFileContentBuilder->build(380 (new PhpClass('TestClass'))381 ->implements(new PhpInterface('TestInterface'), new PhpInterface('TestInterface2'))382 );383 $this->assertStringContainsString('TestClass implements TestInterface, TestInterface2', $phpFileContent);384 }385 public function test_build_should_buildClassThatExtendsClass()386 {387 $phpFileContent = $this->phpFileContentBuilder->build(388 (new PhpClass('TestClass'))389 ->extends(new PhpClass('ParentClass'))390 );391 $this->assertStringContainsString('TestClass extends ParentClass', $phpFileContent);392 }393 public function test_build_should_buildTrait(): void394 {395 $phpFileContent = $this->phpFileContentBuilder->build(396 (new PhpTrait('TestTrait'))397 );398 $this->assertStringContainsString('trait TestTrait', $phpFileContent);399 }400 public function test_build_should_buildTrait_withMethod(): void401 {402 $phpFileContent = $this->phpFileContentBuilder->build(403 (new PhpTrait('TestTrait'))->addMethod(new PhpMethod('test', 'public', PhpType::void()))404 );405 $this->assertStringContainsString('public function test(): void', $phpFileContent);406 }407 public function test_build_should_allowToUseTraitInClasses(): void408 {409 $trait = new PhpTrait('TestTrait');410 $phpFileContent = $this->phpFileContentBuilder->build(411 (new Folder('Test'))->addPhpClass(new PhpClass('TestClass'))->useTraits($trait)412 );413 $this->assertStringContainsString('use App\TestTrait;', $phpFileContent);414 $this->assertStringContainsString('use TestTrait', $phpFileContent);415 }416 public function test()417 {418 $phpClassMetadataBuilderMock = $this->createMock(PhpClassMetadataBuilder::class);419 $phpClassMock = $this->createMock(PhpClass::class);420 $phpClassMetadataBuilderMock->expects(self::atLeastOnce())->method('buildNamespace');421 $phpClassMetadataBuilderMock->expects(self::atLeastOnce())->method('buildClassName')->willReturn('Test');422 $phpFileContentBuilder = new PhpFileContentBuilder($phpClassMetadataBuilderMock);423 $phpFileContentBuilder->build($phpClassMock);424 }425 protected function setUp(): void426 {427 parent::setUp();428 $this->phpFileContentBuilder = new PhpFileContentBuilder(new PhpClassMetadataBuilder(self::APP_PREFIX));429 }430}...

Full Screen

Full Screen

DefaultFallbackGeneratorExtensionTest.php

Source:DefaultFallbackGeneratorExtensionTest.php Github

copy

Full Screen

...14 $this->extension = new DefaultFallbackGeneratorExtension();15 }16 public function testSupports()17 {18 $this->extension->addDefaultMethodFields('testClass', []);19 $this->assertTrue($this->extension->supports(['class' => 'testClass']));20 }21 public function testSupportsWithoutClass()22 {23 $this->assertFalse($this->extension->supports([]));24 }25 public function testSupportsWithoutExtension()26 {27 $this->assertFalse($this->extension->supports(['class' => 'testClass']));28 }29 public function testAddDefaultMethodFields()30 {31 $this->assertAttributeEquals([], 'methodExtensions', $this->extension);32 $this->extension->addDefaultMethodFields('testClass', []);33 $this->assertAttributeEquals(['testClass' => []], 'methodExtensions', $this->extension);34 $this->extension->addDefaultMethodFields('testClass', ['test1' => 'data1']);35 $this->assertAttributeEquals(['testClass' => ['test1' => 'data1']], 'methodExtensions', $this->extension);36 $this->extension->addDefaultMethodFields('testClass', ['test2' => 'data2']);37 $this->assertAttributeEquals(38 ['testClass' => ['test1' => 'data1', 'test2' => 'data2']],39 'methodExtensions',40 $this->extension41 );42 }43 /**44 * @expectedException \InvalidArgumentException45 */46 public function testMethodNotGenerated()47 {48 $class = PhpClass::create('Test\Entity');49 $schema = [50 'class' => 'Test\Entity'51 ];52 $this->extension->generate($schema, $class);...

Full Screen

Full Screen

PhpClassMetadataBuilderTest.php

Source:PhpClassMetadataBuilderTest.php Github

copy

Full Screen

1<?php2/*3 *4 * This file is part of leprz/boilerplate-generator5 *6 * Copyright (c) 2021. Przemek Łęczycki <leczycki.przemyslaw@gmail.com>7 */8declare(strict_types=1);9namespace Leprz\Boilerplate\Tests\Builder;10use Leprz\Boilerplate\Builder\PhpClassMetadataBuilder;11use Leprz\Boilerplate\PathNode\Folder;12use Leprz\Boilerplate\PathNode\Php\PhpClass;13use Leprz\Boilerplate\Tests\UnitTestCase;14/**15 * @package Leprz\Boilerplate\Tests\Builder16 * @covers \Leprz\Boilerplate\Builder\PhpClassMetadataBuilder17 * @uses \Leprz\Boilerplate\PathNode\Php\PhpFile18 * @uses \Leprz\Boilerplate\PathNode\Php\PhpClass19 * @uses \Leprz\Boilerplate\PathNode\Folder20 * @uses \Leprz\Boilerplate\PathNode\File21 * @uses \Leprz\Boilerplate\PathNode\PathNode22 */23class PhpClassMetadataBuilderTest extends UnitTestCase24{25 /**26 * @var \Leprz\Boilerplate\Builder\PhpClassMetadataBuilder27 */28 private PhpClassMetadataBuilder $phpClassMetadataBuilder;29 public function test_buildClassName_should_returnValidClassName()30 {31 $className = $this->phpClassMetadataBuilder->buildClassName(new PhpClass('Test'));32 $this->assertEquals('Test', $className);33 }34 public function test_buildNamespace_should_returnValidNamespace()35 {36 $namespace = $this->phpClassMetadataBuilder->buildNamespace(new PhpClass('Test'));37 $nestedNamespace = $this->phpClassMetadataBuilder->buildNamespace(38 (new Folder('Test'))->addPhpClass(39 new PhpClass('Test')40 )41 );42 $this->assertEquals('App', $namespace);43 $this->assertEquals('App\Test', $nestedNamespace);44 }45 public function test_buildClassMetadataForExistingClass(): void46 {47 $phpClass = PhpClass::fromFQCN("Leprz\Test\TestClass");48 $namespace = $this->phpClassMetadataBuilder->buildNamespace($phpClass);49 $use = $this->phpClassMetadataBuilder->buildUse($phpClass);50 $this->assertEquals('Leprz\Test', $namespace);51 $this->assertEquals('TestClass', $phpClass->getClassName());52 $this->assertEquals('Leprz\Test\TestClass', $use);53 }54 public function test_BuildUse_should_returnValidUse()55 {56 $use = $this->phpClassMetadataBuilder->buildUse(new PhpClass('Test'));57 $this->assertEquals('App\Test', $use);58 }59 protected function setUp(): void60 {61 parent::setUp();62 $this->phpClassMetadataBuilder = new PhpClassMetadataBuilder('App');63 }64}...

Full Screen

Full Screen

testClass

Using AI Code Generation

copy

Full Screen

1$phpClass->testClass();2$phpClass->testClass();3$phpClass->testClass();4$phpClass->testClass();5$phpClass->testClass();6$phpClass->testClass();7$phpClass->testClass();8$phpClass->testClass();9$phpClass->testClass();10$phpClass->testClass();11$phpClass->testClass();12$phpClass->testClass();13$phpClass->testClass();14$phpClass->testClass();15$phpClass->testClass();16$phpClass->testClass();17$phpClass->testClass();18$phpClass->testClass();19$phpClass->testClass();

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful