2018-03-20 00:53:47 +03:00
|
|
|
{-# LANGUAGE OverloadedLists #-}
|
2018-03-20 00:42:00 +03:00
|
|
|
module Analysis.PHP.Spec (spec) where
|
|
|
|
|
2018-05-07 00:37:44 +03:00
|
|
|
import Data.Abstract.Evaluatable (EvalError(..))
|
2018-04-21 17:22:09 +03:00
|
|
|
import qualified Language.PHP.Assignment as PHP
|
2018-04-24 02:47:13 +03:00
|
|
|
import qualified Data.Language as Language
|
2018-04-21 17:22:09 +03:00
|
|
|
|
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-03-27 22:23:26 +03:00
|
|
|
env <- environment . snd <$> evaluate "main.php"
|
2018-04-02 20:40:52 +03:00
|
|
|
env `shouldBe` [ ("foo", addr 0)
|
|
|
|
, ("bar", addr 1) ]
|
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-03-27 22:23:26 +03:00
|
|
|
env <- environment . snd <$> evaluate "main_once.php"
|
2018-04-02 20:40:52 +03:00
|
|
|
env `shouldBe` [ ("foo", addr 0)
|
|
|
|
, ("bar", addr 1) ]
|
2018-03-23 18:57:02 +03:00
|
|
|
|
|
|
|
it "evaluates namespaces" $ do
|
2018-03-27 22:23:26 +03:00
|
|
|
res <- snd <$> evaluate "namespaces.php"
|
2018-04-02 20:40:52 +03:00
|
|
|
environment res `shouldBe` [ ("NS1", addr 0)
|
|
|
|
, ("Foo", addr 6) ]
|
2018-03-27 22:23:26 +03:00
|
|
|
|
2018-04-02 20:40:52 +03:00
|
|
|
heapLookup (Address (Precise 0)) (heap res) `shouldBe` ns "NS1" [ ("Sub1", addr 1)
|
|
|
|
, ("b", addr 4)
|
|
|
|
, ("c", addr 5)
|
2018-03-27 22:23:26 +03:00
|
|
|
]
|
2018-04-02 20:40:52 +03:00
|
|
|
heapLookup (Address (Precise 1)) (heap res) `shouldBe` ns "Sub1" [ ("Sub2", addr 2) ]
|
|
|
|
heapLookup (Address (Precise 2)) (heap res) `shouldBe` ns "Sub2" [ ("f", addr 3) ]
|
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-07 00:30:07 +03:00
|
|
|
evalPHPProject path = testEvaluating <$> evaluateProject phpParser Language.PHP Nothing path
|