Skip to content

Commit f16993b

Browse files
committed
Write ERT tests for sub-namespaces autoloading
Plus split tests between composer and non-composer
1 parent 8021b01 commit f16993b

File tree

7 files changed

+124
-56
lines changed

7 files changed

+124
-56
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
;;; ede-php-autoload-composer-test.el --- Test for ede-php-autoload composer analysis -*- lexical-binding: t -*-
2+
3+
;; Copyright (C) 2015, Steven Rémot
4+
5+
;; Author: Steven Rémot <steven.remot@gmail.com>
6+
;; Homepage: https://github.com/stevenremot/ede-php-autoload
7+
8+
;; This file is not part of GNU Emacs.
9+
10+
;; This program is free software; you can redistribute it and/or
11+
;; modify it under the terms of the GNU General Public License as
12+
;; published by the Free Software Foundation; either version 2, or (at
13+
;; your option) any later version.
14+
15+
;; This program is distributed in the hope that it will be useful, but
16+
;; WITHOUT ANY WARRANTY; without even the implied warranty of
17+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18+
;; General Public License for more details.
19+
20+
;; You should have received a copy of the GNU General Public License
21+
;; along with this program; see the file COPYING. If not, write to
22+
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23+
;; Boston, MA 02111-1307, USA.
24+
25+
;;; Commentary:
26+
;;
27+
28+
;;; Code:
29+
(ert-deftest ede-php-autoload-composer-project-is-defined ()
30+
"The EDE php autoload project should be defined."
31+
(with-current-project-file "main.php" "with-composer"
32+
(should (ede-php-autoload-project-p (ede-current-project)))))
33+
34+
(define-class-definition-test ede-php-autoload-composer-find-psr0 ()
35+
"The definition for a PSR-4 class should be found."
36+
:class "Psr0Ns_TheClass"
37+
:file-name "src/Psr0Ns/TheClass.php"
38+
:project "with-composer")
39+
40+
(define-class-definition-test ede-php-autoload-composer-find-psr4 ()
41+
"The definition for a PSR-4 class should be found."
42+
:class "Psr4Ns\\TheClass"
43+
:file-name "src/Psr4Ns/TheClass.php"
44+
:project "with-composer")
45+
46+
(define-class-definition-test ede-php-autoload-composer-find-multidir-1 ()
47+
"The definition of the first item of a multi-directory namespace should be found."
48+
:class "MultiDirNs\\TheClass1"
49+
:file-name "src/MultiDirNs1/TheClass1.php"
50+
:project "with-composer")
51+
52+
(define-class-definition-test ede-php-autoload-composer-find-multidir-2 ()
53+
"The definition of the non-first item of a multi-directory namespace should be found."
54+
:class "MultiDirNs\\TheClass2"
55+
:file-name "src/MultiDirNs2/TheClass2.php"
56+
:project "with-composer")
57+
58+
(define-class-definition-test ede-php-autoload-composer-find-nothing ()
59+
"nil should be returned when no definition have been found."
60+
:class "Psr4Ns\\DoesNotExist"
61+
:file-name nil
62+
:project "with-composer")
63+
64+
(define-class-definition-test ede-php-autoload-composer-find-third-party ()
65+
"The definition for a composer dependency's class should be found."
66+
:class "ThirdParty\\ThirdClass"
67+
:file-name "vendor/third-party/third-party/src/ThirdClass.php"
68+
:project "with-composer")
69+
70+
(define-class-definition-test ede-php-autoload-composer-find-with-target-dir ()
71+
"The definition for a composer dependency with a target dir should be found."
72+
:class "TargetDir\\Component\\TheClass"
73+
:file-name "vendor/target-dir/target-dir/TargetDir/Component/TheClass.php"
74+
:project "with-composer")
75+
76+
(provide 'ede-php-autoload-composer-test)
77+
78+
;;; ede-php-autoload-composer-test.el ends here

test/ede-php-autoload-test.el

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -26,90 +26,52 @@
2626
;;
2727

2828
;;; Code:
29-
30-
;; Without composer
31-
(ert-deftest ede-php-autoload-wt-composer-project-is-defined ()
29+
(ert-deftest ede-php-autoload-project-is-defined ()
3230
"The EDE php autoload project should be defined."
3331
(with-current-project-file "main.php" "without-composer"
3432
(should (ede-php-autoload-project-p (ede-current-project)))))
3533

36-
(define-class-definition-test ede-php-autoload-wt-composer-find-psr0 ()
34+
(define-class-definition-test ede-php-autoload-find-psr0 ()
3735
"The definition for a PSR-4 class should be found."
3836
:class "Psr0Ns_TheClass"
3937
:file-name "src/Psr0Ns/TheClass.php"
4038
:project "without-composer")
4139

42-
(define-class-definition-test ede-php-autoload-wt-composer-find-psr4 ()
40+
(define-class-definition-test ede-php-autoload-find-psr4 ()
4341
"The definition for a PSR-4 class should be found."
4442
:class "Psr4Ns\\TheClass"
4543
:file-name "src/Psr4Ns/TheClass.php"
4644
:project "without-composer")
4745

48-
(define-class-definition-test ede-php-autoload-wt-composer-find-multidir-1 ()
46+
(define-class-definition-test ede-php-autoload-find-multidir-1 ()
4947
"The definition of the first item of a multi-directory namespace should be found."
5048
:class "MultiDirNs\\TheClass1"
5149
:file-name "src/MultiDirNs1/TheClass1.php"
5250
:project "without-composer")
5351

54-
(define-class-definition-test ede-php-autoload-wt-composer-find-multidir-2 ()
52+
(define-class-definition-test ede-php-autoload-find-multidir-2 ()
5553
"The definition of the non-first item of a multi-directory namespace should be found."
5654
:class "MultiDirNs\\TheClass2"
5755
:file-name "src/MultiDirNs2/TheClass2.php"
5856
:project "without-composer")
5957

60-
(define-class-definition-test ede-php-autoload-wt-composer-find-nothing ()
61-
"nil should be returned when no definition have been found."
62-
:class "Psr4Ns\\DoesNotExist"
63-
:file-name nil
58+
(define-class-definition-test ede-php-autoload-find-psr0-split-without-clash ()
59+
"The definition of a class in a split namespace (iwht multiple sub-namespaces) should be found on PSR-0."
60+
:class "Psr0Split\\Ns2\\TheClass"
61+
:file-name "src/Psr0Split/Ns2/TheClass.php"
6462
:project "without-composer")
6563

66-
;; With composer
67-
(ert-deftest ede-php-autoload-composer-project-is-defined ()
68-
"The EDE php autoload project should be defined."
69-
(with-current-project-file "main.php" "with-composer"
70-
(should (ede-php-autoload-project-p (ede-current-project)))))
71-
72-
(define-class-definition-test ede-php-autoload-composer-find-psr0 ()
73-
"The definition for a PSR-4 class should be found."
74-
:class "Psr0Ns_TheClass"
75-
:file-name "src/Psr0Ns/TheClass.php"
76-
:project "with-composer")
77-
78-
(define-class-definition-test ede-php-autoload-composer-find-psr4 ()
79-
"The definition for a PSR-4 class should be found."
80-
:class "Psr4Ns\\TheClass"
81-
:file-name "src/Psr4Ns/TheClass.php"
82-
:project "with-composer")
83-
84-
(define-class-definition-test ede-php-autoload-composer-find-multidir-1 ()
85-
"The definition of the first item of a multi-directory namespace should be found."
86-
:class "MultiDirNs\\TheClass1"
87-
:file-name "src/MultiDirNs1/TheClass1.php"
88-
:project "with-composer")
89-
90-
(define-class-definition-test ede-php-autoload-composer-find-multidir-2 ()
91-
"The definition of the non-first item of a multi-directory namespace should be found."
92-
:class "MultiDirNs\\TheClass2"
93-
:file-name "src/MultiDirNs2/TheClass2.php"
94-
:project "with-composer")
64+
(define-class-definition-test ede-php-autoload-find-psr4-split-without-clash ()
65+
"The definition of a class in a split namespace (iwht multiple sub-namespaces) should be found on PSR-4."
66+
:class "Psr4Split\\Ns2\\TheClass"
67+
:file-name "src/Psr4Split/Ns2/TheClass.php"
68+
:project "without-composer")
9569

96-
(define-class-definition-test ede-php-autoload-composer-find-nothing ()
70+
(define-class-definition-test ede-php-autoload-find-nothing ()
9771
"nil should be returned when no definition have been found."
9872
:class "Psr4Ns\\DoesNotExist"
9973
:file-name nil
100-
:project "with-composer")
101-
102-
(define-class-definition-test ede-php-autoload-composer-find-third-party ()
103-
"The definition for a composer dependency's class should be found."
104-
:class "ThirdParty\\ThirdClass"
105-
:file-name "vendor/third-party/third-party/src/ThirdClass.php"
106-
:project "with-composer")
107-
108-
(define-class-definition-test ede-php-autoload-composer-find-with-target-dir ()
109-
"The definition for a composer dependency with a target dir should be found."
110-
:class "TargetDir\\Component\\TheClass"
111-
:file-name "vendor/target-dir/target-dir/TargetDir/Component/TheClass.php"
112-
:project "with-composer")
74+
:project "without-composer")
11375

11476
(provide 'ede-php-autoload-test)
11577

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace Psr0Split\Ns1;
3+
4+
class TheClass
5+
{
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace Psr0Split\Ns2;
3+
4+
class TheClass
5+
{
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace Psr4Split\Ns1;
3+
4+
class TheClass
5+
{
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace Psr4Split\Ns2;
3+
4+
class TheClass
5+
{
6+
}

test/test-helper.el

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@
5151
(ede-php-autoload-project "Without composer"
5252
:file (concat test-helper--projects-root
5353
"without-composer/main.php")
54-
:class-autoloads '(:psr-0 (("Psr0Ns" . "src/Psr0Ns"))
54+
:class-autoloads '(:psr-0 (("Psr0Ns" . "src/Psr0Ns")
55+
("Psr0Split\\Ns1" . "src/Psr0Split/Ns1")
56+
("Psr0Split\\Ns2" . "src/Psr0Split/Ns2"))
5557
:psr-4 (("Psr4Ns" . "src/Psr4Ns")
56-
("MultiDirNs" . ("src/MultiDirNs1" "src/MultiDirNs2")))))
58+
("MultiDirNs" . ("src/MultiDirNs1" "src/MultiDirNs2"))
59+
("Psr4Split\\Ns1" . "src/Psr4Split/Ns1")
60+
("Psr4Split\\Ns2" . "src/Psr4Split/Ns2"))))
5761

5862
;; Define function helpers
5963
(defun test-helper-get-project-file-path (file project)

0 commit comments

Comments
 (0)