2018-03-20 00:42:00 +03:00
|
|
|
module Analysis.PHP.Spec (spec) where
|
|
|
|
|
2018-05-28 22:44:48 +03:00
|
|
|
import Control.Abstract
|
2018-05-10 17:03:59 +03:00
|
|
|
import Data.Abstract.Environment as Env
|
2018-05-07 00:37:44 +03:00
|
|
|
import Data.Abstract.Evaluatable (EvalError(..))
|
2018-04-24 02:47:13 +03:00
|
|
|
import qualified Data.Language as Language
|
2018-05-28 16:35:42 +03:00
|
|
|
import qualified Language.PHP.Assignment as PHP
|
2018-03-20 00:42:00 +03:00
|
|
|
import SpecHelpers
|
|
|
|
|
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = parallel $ do
|
2018-03-23 18:57:02 +03:00
|
|
|
describe "PHP" $ do
|
|
|
|
it "evaluates include and require" $ do
|
2018-05-28 22:44:48 +03:00
|
|
|
((res, state), _) <- evaluate "main.php"
|
2018-05-28 23:06:25 +03:00
|
|
|
res `shouldBe` Right [unit]
|
2018-05-28 22:44:48 +03:00
|
|
|
Env.names (environment state) `shouldBe` [ "bar", "foo" ]
|
2018-03-21 02:46:32 +03:00
|
|
|
|
2018-03-23 18:57:02 +03:00
|
|
|
it "evaluates include_once and require_once" $ do
|
2018-05-28 22:44:48 +03:00
|
|
|
((res, state), _) <- evaluate "main_once.php"
|
2018-05-28 23:06:25 +03:00
|
|
|
res `shouldBe` Right [unit]
|
2018-05-28 22:44:48 +03:00
|
|
|
Env.names (environment state) `shouldBe` [ "bar", "foo" ]
|
2018-03-23 18:57:02 +03:00
|
|
|
|
|
|
|
it "evaluates namespaces" $ do
|
2018-05-10 17:58:24 +03:00
|
|
|
((_, state), _) <- evaluate "namespaces.php"
|
|
|
|
Env.names (environment state) `shouldBe` [ "Foo", "NS1" ]
|
2018-05-10 17:03:59 +03:00
|
|
|
|
2018-05-10 17:58:24 +03:00
|
|
|
(derefQName (heap state) ("NS1" :| []) (environment state) >>= deNamespace) `shouldBe` Just ("NS1", ["Sub1", "b", "c"])
|
|
|
|
(derefQName (heap state) ("NS1" :| ["Sub1"]) (environment state) >>= deNamespace) `shouldBe` Just ("Sub1", ["Sub2"])
|
|
|
|
(derefQName (heap state) ("NS1" :| ["Sub1", "Sub2"]) (environment state) >>= deNamespace) `shouldBe` Just ("Sub2", ["f"])
|
2018-03-20 00:42:00 +03:00
|
|
|
|
|
|
|
where
|
|
|
|
fixtures = "test/fixtures/php/analysis/"
|
2018-04-02 21:37:01 +03:00
|
|
|
evaluate entry = evalPHPProject (fixtures <> entry)
|
2018-05-28 16:55:01 +03:00
|
|
|
evalPHPProject path = testEvaluating <$> evaluateProject phpParser Language.PHP Nothing path
|