Beispiel #1
0
 def test_write_class_with_empty(self):
     result = PHPFile.write_class(self.empty_file_path, 'TestPlugin')
     content = ''
     with open(self.empty_file_path, 'r') as file_content:
         content = file_content.read()
     self.assertTrue(result)
     self.assertIn('class TestPlugin', content)
Beispiel #2
0
 def test_write_class_with_file_doesnt_exists(self):
     result = PHPFile.write_class(self.no_file_path, 'TestPlugin')
     content = ''
     with open(self.no_file_path, 'r') as file_content:
         content = file_content.read()
     self.assertTrue(result)
     self.assertIn('class TestPlugin', content)
     self.assertIn('<?php', content)
Beispiel #3
0
 def test_add_method_with_class_in_file(self):
     self.method_data.class_file_path = self.test_dir + os.sep + 'test_file'
     with open(self.method_data.class_file_path, 'a') as test_file:
         test_file.write('class TestPlugin {\n\n}')
         test_file.close()
     self.assertTrue(PHPFile.add_method(self.method_data))
     with open(self.method_data.class_file_path, 'r') as test_file:
         self.assertIn('function testMethod()', test_file.read())
Beispiel #4
0
 def test_write_method_in_class_with_empty_class(self):
     self.method_data.class_file_path = self.empty_class_file_path
     self.method_data.class_name = 'EmptyClass'
     result = PHPFile.write_method_in_class(self.method_data)
     content = ''
     with open(self.empty_class_file_path, 'r') as file_content:
         content = file_content.read()
     self.assertTrue(result)
     self.assertIn('testMethod', content)
Beispiel #5
0
 def test_write_method_in_class_private_method(self):
     self.method_data.class_file_path = self.class_file_path
     self.method_data.method_visibility = 'private'
     self.method_data.method_name = 'testMethod2'
     result = PHPFile.write_method_in_class(self.method_data)
     content = ''
     with open(self.class_file_path, 'r') as file_content:
         content = file_content.read()
     self.assertTrue(result)
     self.assertIn('private function testMethod2', content)
Beispiel #6
0
 def test_write_method_in_class_static_method(self):
     self.method_data.class_file_path = self.class_file_path
     self.method_data.method_is_static = True
     self.method_data.method_name = 'testMethod2'
     result = PHPFile.write_method_in_class(self.method_data)
     content = ''
     with open(self.class_file_path, 'r') as file_content:
         content = file_content.read()
     self.assertTrue(result)
     self.assertIn('static function testMethod2', content)
Beispiel #7
0
 def test_check_if_method_exists_class_without(self):
     result = PHPFile.check_class(self.empty_class_file_path, 'TestPlugin')
     self.assertFalse(result)
Beispiel #8
0
 def test_check_if_method_exists_class_with_the_method(self):
     result = PHPFile.check_class(self.class_file_path, 'TestPlugin')
     self.assertTrue(result)
Beispiel #9
0
 def test_check_if_method_exists_with_empty_file(self):
     result = PHPFile.check_class(self.empty_file_path, 'TestClass')
     self.assertFalse(result)
Beispiel #10
0
 def test_check_class_with_class(self):
     result = PHPFile.check_class(self.class_file_path, 'TestPlugin')
     self.assertTrue(result)
Beispiel #11
0
 def test_check_class_without_file(self):
     result = PHPFile.check_class(self.no_file_path, 'TestPlugin')
     self.assertFalse(result)
Beispiel #12
0
 def test_add_method_with_only_method_in_file(self):
     self.method_data.class_file_path = self.test_dir + os.sep + 'test_file'
     with open(self.method_data.class_file_path, 'a') as test_file:
         test_file.write('testMethod()')
         test_file.close()
     self.assertFalse(PHPFile.add_method(self.method_data))
Beispiel #13
0
 def test_add_method_with_empty_file(self):
     self.method_data.class_file_path = self.test_dir + os.sep + 'empty_file'
     open(self.method_data.class_file_path, 'a').close()
     self.assertFalse(PHPFile.add_method(self.method_data))
Beispiel #14
0
 def test_add_method_without_file(self):
     self.method_data.class_file_path = self.test_dir + os.sep + 'no_file'
     self.assertFalse(PHPFile.add_method(self.method_data))
Beispiel #15
0
 def test_write_method_in_class_without_file(self):
     self.method_data.class_file_path = self.no_file_path
     result = PHPFile.write_method_in_class(self.method_data)
     self.assertFalse(result)