@@ -85,4 +85,59 @@ public function setContentsReplacesContentsSetInPreviousCall(): void
85
85
86
86
self ::assertSame ($ contents2 , $ this ->subject ->getContents ());
87
87
}
88
+
89
+ /**
90
+ * @test
91
+ */
92
+ public function insertContentBeforeInsertsContentBeforeSibbling ()
93
+ {
94
+ $ bogusOne = new DeclarationBlock ();
95
+ $ bogusOne ->setSelectors ('.bogus-one ' );
96
+ $ bogusTwo = new DeclarationBlock ();
97
+ $ bogusTwo ->setSelectors ('.bogus-two ' );
98
+
99
+ $ item = new DeclarationBlock ();
100
+ $ item ->setSelectors ('.item ' );
101
+
102
+ $ sibling = new DeclarationBlock ();
103
+ $ sibling ->setSelectors ('.sibling ' );
104
+
105
+ $ this ->subject ->setContents ([$ bogusOne , $ sibling , $ bogusTwo ]);
106
+
107
+ self ::assertCount (3 , $ this ->subject ->getContents ());
108
+
109
+ $ this ->subject ->insertBefore ($ item , $ sibling );
110
+
111
+ self ::assertCount (4 , $ this ->subject ->getContents ());
112
+ self ::assertSame ([$ bogusOne , $ item , $ sibling , $ bogusTwo ], $ this ->subject ->getContents ());
113
+ }
114
+
115
+ /**
116
+ * @test
117
+ */
118
+ public function insertContentBeforeAppendsIfSibblingNotFound ()
119
+ {
120
+ $ bogusOne = new DeclarationBlock ();
121
+ $ bogusOne ->setSelectors ('.bogus-one ' );
122
+ $ bogusTwo = new DeclarationBlock ();
123
+ $ bogusTwo ->setSelectors ('.bogus-two ' );
124
+
125
+ $ item = new DeclarationBlock ();
126
+ $ item ->setSelectors ('.item ' );
127
+
128
+ $ sibling = new DeclarationBlock ();
129
+ $ sibling ->setSelectors ('.sibling ' );
130
+
131
+ $ orphan = new DeclarationBlock ();
132
+ $ orphan ->setSelectors ('.forever-alone ' );
133
+
134
+ $ this ->subject ->setContents ([$ bogusOne , $ sibling , $ bogusTwo ]);
135
+
136
+ self ::assertCount (3 , $ this ->subject ->getContents ());
137
+
138
+ $ this ->subject ->insertBefore ($ item , $ orphan );
139
+
140
+ self ::assertCount (4 , $ this ->subject ->getContents ());
141
+ self ::assertSame ([$ bogusOne , $ sibling , $ bogusTwo , $ item ], $ this ->subject ->getContents ());
142
+ }
88
143
}
0 commit comments