예제 #1
0
 public function testBasicExample()
 {
     $results = AnalyzeFiles::directory($this->directory)->execute(function ($file) {
         $file->fileIs('sub1/sub1.php');
         $file->action(function ($action) {
             $action->whereNoSearch('Carlos');
             $action->whereSearch('Jorge');
             $action->replace('Jorge', 'Carlos');
         });
         $file->action(function ($action) {
             $action->whereSearch('Example1');
             $action->replace('Hi', 'Bye');
         });
     }, false);
     // For no executing
     $this->assertTrue(is_array($results));
     $this->assertTrue(is_array($results['sub1/sub1.php']));
     $this->assertEquals(2, count($results['sub1/sub1.php']));
     // Two actions
     $this->assertTrue(isset($results['sub1/sub1.php'][0]['requirements'][0]['function']));
     $this->assertTrue(isset($results['sub1/sub1.php'][0]['requirements'][0]['value']));
 }
 function testSelectSubdirectories()
 {
     $results = AnalyzeFiles::rules()->directory($this->directory)->create(function ($rules) {
         $rules->add(function ($data) {
             $data->fileEndsWith('.php');
             $data->filesInside(array('sub1', 'sub2'));
             $data->validation(function ($validation) {
                 $validation->whereSearch('Carlos');
             });
         });
     });
     $this->assertTrue(is_array($results));
     $this->assertFalse($results['sub1/sub1.php']['result']);
     $this->assertTrue($results['sub2/sub2.php']['result']);
 }