| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Copyright 2017 NanoSector | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * You should have received a copy of the MIT license with the project. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * See the LICENSE file for more information. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Yoshi2889\Container\ComponentContainer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class ComponentContainerTest extends TestCase | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	public function testContainerGet() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 		$container = new ComponentContainer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 		$sampleComponent = new \Yoshi2889\Container\Tests\SampleComponent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 		$container->add($sampleComponent); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		$sampleComponentFromContainer = \Yoshi2889\Container\Tests\SampleComponent::fromContainer($container); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		self::assertInstanceOf(\Yoshi2889\Container\Tests\SampleComponent::class, $sampleComponentFromContainer); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 		self::assertEquals($sampleComponent, $sampleComponentFromContainer); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 		$this->expectException(\Yoshi2889\Container\NotFoundException::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 		$container->get(\Yoshi2889\Container\Tests\SampleInvalidComponent::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 		$this->expectException(\Yoshi2889\Container\ContainerException::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 		$container->get(10); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 		$emptyContainer = new ComponentContainer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 		self::assertNull(\Yoshi2889\Container\Tests\SampleComponent::fromContainer($emptyContainer)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 36 |  |  | 	public function testContainerHas() | 
            
                                                        
            
                                    
            
            
                | 37 |  |  | 	{ | 
            
                                                        
            
                                    
            
            
                | 38 |  |  | 		$container = new ComponentContainer(); | 
            
                                                        
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 40 |  |  | 		self::assertFalse($container->has(\Yoshi2889\Container\Tests\SampleComponent::class)); | 
            
                                                        
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 42 |  |  | 		$sampleComponent = new \Yoshi2889\Container\Tests\SampleComponent(); | 
            
                                                        
            
                                    
            
            
                | 43 |  |  | 		$container->add($sampleComponent); | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 45 |  |  | 		self::assertTrue($container->has(\Yoshi2889\Container\Tests\SampleComponent::class)); | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 47 |  |  | 		$this->expectException(\Yoshi2889\Container\ContainerException::class); | 
            
                                                        
            
                                    
            
            
                | 48 |  |  | 		$container->has(10); | 
            
                                                        
            
                                    
            
            
                | 49 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 50 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |  | 
            
                        
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.