@@ -79,4 +79,92 @@ public function testLeadingBackslash() : void
7979 self ::assertSame ('App \\Models ' , $ fqcn ->namespace ?->namespace);
8080 self ::assertSame ('App \\Models \\User ' , (string ) $ fqcn );
8181 }
82+
83+ public function testIsInNamespace () : void
84+ {
85+ $ fqcn1 = new FullyQualified ('App \\Models \\User ' );
86+ $ fqcn2 = new FullyQualified ('User ' );
87+
88+ $ appModels = new NamespaceName ('App \\Models ' );
89+ $ app = new NamespaceName ('App ' );
90+ $ core = new NamespaceName ('Core ' );
91+
92+ self ::assertTrue ($ fqcn1 ->isInNamespace ($ appModels ));
93+ self ::assertFalse ($ fqcn1 ->isInNamespace ($ app ));
94+ self ::assertFalse ($ fqcn1 ->isInNamespace ($ core ));
95+ self ::assertFalse ($ fqcn1 ->isInNamespace (null ));
96+
97+ self ::assertFalse ($ fqcn2 ->isInNamespace ($ appModels ));
98+ self ::assertFalse ($ fqcn2 ->isInNamespace ($ app ));
99+ self ::assertTrue ($ fqcn2 ->isInNamespace (null )); // Class without namespace
100+ }
101+
102+ public function testGetRelativePathFrom () : void
103+ {
104+ $ fqcn = new FullyQualified ('App \\Models \\User \\Profile ' );
105+
106+ $ app = new NamespaceName ('App ' );
107+ $ appModels = new NamespaceName ('App \\Models ' );
108+ $ appModelsUser = new NamespaceName ('App \\Models \\User ' );
109+ $ core = new NamespaceName ('Core ' );
110+
111+ // Direct children and sub-namespaces
112+ self ::assertSame ('Models \\User \\Profile ' , $ fqcn ->getRelativePathFrom ($ app ));
113+ self ::assertSame ('User \\Profile ' , $ fqcn ->getRelativePathFrom ($ appModels ));
114+ self ::assertSame ('Profile ' , $ fqcn ->getRelativePathFrom ($ appModelsUser ));
115+
116+ // Not in a sub-namespace - returns full path
117+ self ::assertSame ('App \\Models \\User \\Profile ' , $ fqcn ->getRelativePathFrom ($ core ));
118+
119+ // Null namespace
120+ self ::assertSame ('App \\Models \\User \\Profile ' , $ fqcn ->getRelativePathFrom (null ));
121+ }
122+
123+ public function testGetRelativePathFromForClassWithoutNamespace () : void
124+ {
125+ $ fqcn = new FullyQualified ('SimpleClass ' );
126+
127+ $ app = new NamespaceName ('App ' );
128+
129+ self ::assertSame ('SimpleClass ' , $ fqcn ->getRelativePathFrom ($ app ));
130+ self ::assertSame ('SimpleClass ' , $ fqcn ->getRelativePathFrom (null ));
131+ }
132+
133+ public function testMaybeFromString () : void
134+ {
135+ // Test with string input
136+ $ result1 = FullyQualified::maybeFromString ('App \\Models \\User ' );
137+ // @phpstan-ignore-next-line
138+ self ::assertNotNull ($ result1 );
139+ self ::assertSame ('App \\Models \\User ' , (string ) $ result1 );
140+
141+ // Test with null input
142+ $ result2 = FullyQualified::maybeFromString (null );
143+ // @phpstan-ignore-next-line
144+ self ::assertNull ($ result2 );
145+
146+ // Test with existing FullyQualified instance
147+ $ existing = new FullyQualified ('App \\Services \\UserService ' );
148+ $ result3 = FullyQualified::maybeFromString ($ existing );
149+ self ::assertSame ($ existing , $ result3 );
150+
151+ // Test with NamespaceName instance
152+ $ namespaceName = new NamespaceName ('App \\Models ' );
153+ $ result4 = FullyQualified::maybeFromString ($ namespaceName );
154+ // @phpstan-ignore-next-line
155+ self ::assertNotNull ($ result4 );
156+ self ::assertSame ('App \\Models ' , (string ) $ result4 );
157+ }
158+
159+ public function testEquals () : void
160+ {
161+ $ fqcn1 = new FullyQualified ('App \\Models \\User ' );
162+ $ fqcn2 = new FullyQualified ('App ' , 'Models ' , 'User ' );
163+ $ fqcn3 = new FullyQualified ('App \\Models \\Post ' );
164+ $ fqcn4 = new FullyQualified ('User ' );
165+
166+ self ::assertTrue ($ fqcn1 ->equals ($ fqcn2 ));
167+ self ::assertFalse ($ fqcn1 ->equals ($ fqcn3 ));
168+ self ::assertFalse ($ fqcn1 ->equals ($ fqcn4 ));
169+ }
82170}
0 commit comments